benchmark: fix copy'n'past of the file-description comment
[platform/upstream/gstreamer.git] / tests / benchmarks / tracerserialize.c
1 /* GStreamer
2  * Copyright (C) 2016 Stefan Sauer <ensonic@users.sf.net>
3  *
4  * tracerserialize.c: benchmark for log serialisation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITcreating %d capsNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /* to check the sizes run:
23  *
24  * GST_DEBUG="default:7" GST_DEBUG_FILE=trace.log ./tracerserialize
25  *
26  * grep "log_gst_structure" trace.log >tracerserialize.gststructure.log
27  * grep "log_g_variant" trace.log >tracerserialize.gvariant.log
28  *
29  */
30
31 #include <gst/gst.h>
32
33 #define NUM_LOOPS 100000
34
35 static void
36 log_gst_structure (const gchar * name, const gchar * first, ...)
37 {
38   va_list var_args;
39   GstStructure *s;
40   gchar *l;
41
42   va_start (var_args, first);
43   s = gst_structure_new_valist (name, first, var_args);
44   l = gst_structure_to_string (s);
45   GST_TRACE ("%s", l);
46   g_free (l);
47   gst_structure_free (s);
48   va_end (var_args);
49 }
50
51 static void
52 log_g_variant (const gchar * format, ...)
53 {
54   va_list var_args;
55   GVariant *v;
56   gchar *l;
57
58   va_start (var_args, format);
59   v = g_variant_new_va (format, NULL, &var_args);
60   l = g_variant_print (v, FALSE);
61   GST_TRACE ("%s", l);
62   g_free (l);
63   g_variant_unref (v);
64   va_end (var_args);
65 }
66
67 gint
68 main (gint argc, gchar * argv[])
69 {
70   GstClockTime start, end;
71   gint i;
72
73   gst_init (&argc, &argv);
74
75   start = gst_util_get_timestamp ();
76   for (i = 0; i < NUM_LOOPS; i++) {
77     log_gst_structure ("name",
78         "ts", G_TYPE_UINT64, (guint64) 0,
79         "index", G_TYPE_UINT, 10,
80         "test", G_TYPE_STRING, "hallo",
81         "flag", GST_TYPE_PAD_DIRECTION, GST_PAD_SRC, NULL);
82   }
83   end = gst_util_get_timestamp ();
84   g_print ("%" GST_TIME_FORMAT ": GstStructure\n", GST_TIME_ARGS (end - start));
85
86   start = gst_util_get_timestamp ();
87   for (i = 0; i < NUM_LOOPS; i++) {
88     log_g_variant ("(stusu)", "name", (guint64) 0, 10, "hallo", GST_PAD_SRC);
89   }
90   end = gst_util_get_timestamp ();
91   g_print ("%" GST_TIME_FORMAT ": GVariant\n", GST_TIME_ARGS (end - start));
92 }