2 * Copyright (C) 2016 Stefan Sauer <ensonic@users.sf.net>
4 * tracerserialize.c: benchmark for log serialisation
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.
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.
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.
22 /* to check the sizes run:
24 * GST_DEBUG="default:7" GST_DEBUG_FILE=trace.log ./tracerserialize
26 * grep "log_gst_structure" trace.log >tracerserialize.gststructure.log
27 * grep "log_g_variant" trace.log >tracerserialize.gvariant.log
33 #define NUM_LOOPS 100000
36 log_gst_structure (const gchar * name, const gchar * first, ...)
42 va_start (var_args, first);
43 s = gst_structure_new_valist (name, first, var_args);
44 l = gst_structure_to_string (s);
47 gst_structure_free (s);
52 log_gst_structure_tmpl (const gchar * format, ...)
56 va_start (var_args, format);
57 if (G_LIKELY (GST_LEVEL_TRACE <= _gst_debug_min)) {
58 gst_debug_log_valist (GST_CAT_DEFAULT, GST_LEVEL_TRACE, __FILE__,
59 GST_FUNCTION, __LINE__, NULL, format, var_args);
65 log_g_variant (const gchar * format, ...)
71 va_start (var_args, format);
72 v = g_variant_new_va (format, NULL, &var_args);
73 l = g_variant_print (v, FALSE);
81 main (gint argc, gchar * argv[])
83 GstClockTime start, end;
86 gst_init (&argc, &argv);
88 start = gst_util_get_timestamp ();
89 for (i = 0; i < NUM_LOOPS; i++) {
90 log_gst_structure ("name",
91 "ts", G_TYPE_UINT64, (guint64) 0,
92 "index", G_TYPE_UINT, 10,
93 "test", G_TYPE_STRING, "hallo",
94 "bool", G_TYPE_BOOLEAN, TRUE,
95 "flag", GST_TYPE_PAD_DIRECTION, GST_PAD_SRC, NULL);
97 end = gst_util_get_timestamp ();
98 g_print ("%" GST_TIME_FORMAT ": GstStructure\n", GST_TIME_ARGS (end - start));
100 start = gst_util_get_timestamp ();
101 for (i = 0; i < NUM_LOOPS; i++) {
102 log_gst_structure_tmpl ("name, ts=(guint64)%" G_GUINT64_FORMAT
103 ", index=(uint)%u, test=(string)%s, bool=(boolean)%s, flag=(GstPadDirection)%d;",
104 (guint64) 0, 10, "hallo", (TRUE ? "true" : "false"), GST_PAD_SRC);
106 end = gst_util_get_timestamp ();
107 g_print ("%" GST_TIME_FORMAT ": GstStructure template\n",
108 GST_TIME_ARGS (end - start));
110 start = gst_util_get_timestamp ();
111 for (i = 0; i < NUM_LOOPS; i++) {
112 log_g_variant ("(stusbu)", "name", (guint64) 0, 10, "hallo", TRUE,
115 end = gst_util_get_timestamp ();
116 g_print ("%" GST_TIME_FORMAT ": GVariant\n", GST_TIME_ARGS (end - start));