tests/instantiate/: Add test to test speed of caps copy and free.
[platform/upstream/gstreamer.git] / tests / benchmarks / caps.c
1 /* GStreamer
2  * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3  *
4  * caps.c: benchmark for caps creation and destruction
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 FITNESS 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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 #include <gst/gst.h>
24
25
26 #define NUM_CAPS 10000
27
28
29 #define GST_AUDIO_INT_PAD_TEMPLATE_CAPS \
30   "audio/x-raw-int, " \
31   "rate = (int) [ 1, MAX ], " \
32   "channels = (int) [ 1, MAX ], " \
33   "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \
34   "width = (int) { 8, 16, 24, 32 }, " \
35   "depth = (int) [ 1, 32 ], " \
36   "signed = (boolean) { true, false }"
37
38
39 static GstClockTime
40 gst_get_current_time (void)
41 {
42   GTimeVal tv;
43
44   g_get_current_time (&tv);
45   return GST_TIMEVAL_TO_TIME (tv);
46 }
47
48
49 gint
50 main (gint argc, gchar * argv[])
51 {
52   GstCaps **capses;
53   GstCaps *protocaps;
54   GstClockTime start, end;
55   gint i;
56
57   gst_init (&argc, &argv);
58
59   protocaps = gst_caps_from_string (GST_AUDIO_INT_PAD_TEMPLATE_CAPS);
60
61   start = gst_get_current_time ();
62   capses = g_new (GstCaps *, NUM_CAPS);
63   for (i = 0; i < NUM_CAPS; i++)
64     capses[i] = gst_caps_copy (protocaps);
65   end = gst_get_current_time ();
66   g_print ("%" GST_TIME_FORMAT " - creating %d caps\n",
67       GST_TIME_ARGS (end - start), i);
68
69   start = gst_get_current_time ();
70   for (i = 0; i < NUM_CAPS; i++)
71     gst_caps_unref (capses[i]);
72   end = gst_get_current_time ();
73   g_print ("%" GST_TIME_FORMAT " - destroying %d caps\n",
74       GST_TIME_ARGS (end - start), i);
75
76   g_free (capses);
77   gst_caps_unref (protocaps);
78
79   return 0;
80 }