7 #include <gst/base/gstadapter.h>
16 /* This test pushes 'n' buffers of 'write size' into an adapter, then reads
17 * them out in 'read size' sized pieces, using take and then take_buffer,
18 * and prints the timings */
20 static struct TestParams param_sets[] = {
21 /* These values put ~256MB in 1MB chunks in an adapter, then reads them out
23 {256000000, 250000, 1000000},
24 /* These values put ~256MB in 1000 byte chunks in an adapter, then reads them
25 * out in 200 byte blocks */
26 {25600000, 200, 1000},
27 /* These values put ~256MB in 200 chunks in an adapter, then reads them out
28 * in 1000 byte blocks */
31 static const gint n_tests = sizeof (param_sets) / sizeof (struct TestParams);
33 static gint ticks_per_sec;
36 run_test_take (struct TestParams *params)
38 /* Create an adapter and feed it data of fixed size, then retrieve it in
40 GstAdapter *adapter = gst_adapter_new ();
44 gint ntimes = params->tot_size / params->write_size;
46 for (i = 0; i < ntimes; i++) {
47 buf = gst_buffer_new_and_alloc (params->write_size);
48 memset (GST_BUFFER_DATA (buf), 0, params->write_size);
50 gst_adapter_push (adapter, buf);
54 data = gst_adapter_take (adapter, params->read_size);
60 g_object_unref (adapter);
64 run_test_take_buffer (struct TestParams *params)
66 /* Create an adapter and feed it data of fixed size, then retrieve it in
69 GstAdapter *adapter = gst_adapter_new ();
72 gint ntimes = params->tot_size / params->write_size;
74 for (i = 0; i < ntimes; i++) {
75 buf = gst_buffer_new_and_alloc (params->write_size);
76 memset (GST_BUFFER_DATA (buf), 0, params->write_size);
78 gst_adapter_push (adapter, buf);
82 buf = gst_adapter_take_buffer (adapter, params->read_size);
85 gst_buffer_unref (buf);
88 g_object_unref (adapter);
92 run_tests (struct TestParams *params)
98 g_print ("Running on %d bytes, writing %d bytes/buf, reading %d bytes/buf\n",
99 params->tot_size, params->write_size, params->read_size);
102 run_test_take (params);
105 dur = (gdouble) (time_data.tms_utime + time_data.tms_stime) / ticks_per_sec;
106 g_print ("Time for take test: %g secs\n", dur - start);
109 run_test_take_buffer (params);
112 dur = (gdouble) (time_data.tms_utime + time_data.tms_stime) / ticks_per_sec;
113 g_print ("Time for TakeBuffer test: %g secs\n", dur - start);
119 main (int argc, char **argv)
123 ticks_per_sec = sysconf (_SC_CLK_TCK);
125 gst_init (&argc, &argv);
127 for (i = 0; i < n_tests; i++)
128 run_tests (param_sets + i);