tests/: add simple benchmark to test various speeds of fakesrc ! identity ! identity...
[platform/upstream/gstreamer.git] / tests / benchmarks / mass-elements.c
1 /*
2  * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <gst/gst.h>
20
21 #define IDENTITY_COUNT (1000)
22 #define BUFFER_COUNT (1000)
23
24
25 static GstClockTime
26 gst_get_current_time (void)
27 {
28   GTimeVal tv;
29
30   g_get_current_time (&tv);
31   return GST_TIMEVAL_TO_TIME (tv);
32 }
33
34 gint
35 main (gint argc, gchar * argv[])
36 {
37   GstElement *pipeline, *src, *sink, *current, *last;
38   guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
39   GstClockTime start, end;
40
41   gst_init (&argc, &argv);
42
43   if (argc > 1)
44     identities = atoi (argv[1]);
45   if (argc > 2)
46     buffers = atoi (argv[2]);
47
48   g_print
49       ("*** benchmarking this pipeline: fakesrc num-buffers=%u ! %u * identity ! fakesink\n",
50       buffers, identities);
51   start = gst_get_current_time ();
52   pipeline = gst_element_factory_make ("pipeline", NULL);
53   g_assert (pipeline);
54   src = gst_element_factory_make ("fakesrc", NULL);
55   g_assert (src);
56   g_object_set (src, "num-buffers", buffers, NULL);
57   sink = gst_element_factory_make ("fakesink", NULL);
58   g_assert (sink);
59   last = src;
60   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
61   for (i = 0; i < identities; i++) {
62     current = gst_element_factory_make ("identity", NULL);
63     g_assert (current);
64     gst_bin_add (GST_BIN (pipeline), current);
65     if (!gst_element_link (last, current))
66       g_assert_not_reached ();
67     last = current;
68   }
69   if (!gst_element_link (last, sink))
70     g_assert_not_reached ();
71   end = gst_get_current_time ();
72   g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
73       GST_TIME_ARGS (end - start), identities);
74
75   start = gst_get_current_time ();
76   if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
77     g_assert_not_reached ();
78   end = gst_get_current_time ();
79   g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
80       GST_TIME_ARGS (end - start));
81
82   start = gst_get_current_time ();
83   while (gst_bin_iterate (GST_BIN (pipeline)));
84   end = gst_get_current_time ();
85   g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
86       GST_TIME_ARGS (end - start), buffers);
87
88   start = gst_get_current_time ();
89   g_object_unref (pipeline);
90   end = gst_get_current_time ();
91   g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
92       GST_TIME_ARGS (end - start));
93
94   return 0;
95 }