3 from structure import Structure
4 from gi.repository import Gst
7 PLAIN_STRUCTURE = r'thread-rusage, thread-id=(guint64)37268592, ts=(guint64)79416000, average-cpuload=(uint)1000, current-cpuload=(uint)1000, time=(guint64)79418045;'
8 NESTED_STRUCTURE = r'latency.class, src=(structure)"scope\,\ type\=\(type\)gchararray\,\ related-to\=\(GstTracerValueScope\)GST_TRACER_VALUE_SCOPE_PAD\;", sink=(structure)"scope\,\ type\=\(type\)gchararray\,\ related-to\=\(GstTracerValueScope\)GST_TRACER_VALUE_SCOPE_PAD\;", time=(structure)"value\,\ type\=\(type\)guint64\,\ description\=\(string\)\"time\\\ it\\\ took\\\ for\\\ the\\\ buffer\\\ to\\\ go\\\ from\\\ src\\\ to\\\ sink\\\ ns\"\,\ flags\=\(GstTracerValueFlags\)GST_TRACER_VALUE_FLAGS_AGGREGATED\,\ min\=\(guint64\)0\,\ max\=\(guint64\)18446744073709551615\;";'
10 NAT_STRUCTURE = Structure(PLAIN_STRUCTURE)
11 GI_STRUCTURE = Gst.Structure.from_string(PLAIN_STRUCTURE)[0]
16 def nat_parse_plain():
17 s = Structure(PLAIN_STRUCTURE)
20 def nat_parse_nested():
21 s = Structure(NESTED_STRUCTURE)
25 return NAT_STRUCTURE.name
29 return NAT_STRUCTURE.values['thread-id']
32 # gstreamer impl via gi
35 s = Gst.Structure.from_string(PLAIN_STRUCTURE)[0]
38 def gi_parse_nested():
39 s = Gst.Structure.from_string(NESTED_STRUCTURE)[0]
43 return GI_STRUCTURE.get_name()
47 return GI_STRUCTURE.get_value('thread-id')
52 def perf(method, n, flavor):
53 t = timeit.timeit(method + '()', 'from __main__ import ' + method, number=n)
54 print("%6s: %lf s, (%lf calls/s)" % (flavor, t, (n / t)))
57 if __name__ == '__main__':
59 parser = argparse.ArgumentParser()
60 parser.add_argument('-i', '--iterations', default=10000, type=int,
61 help='number of iterations (default: 10000)')
62 args = parser.parse_args()
66 t = perf('nat_parse_plain', n, 'native')
67 t = perf('gi_parse_plain', n, 'gi')
69 print("parse_nested:")
70 t = perf('nat_parse_nested', n, 'native')
71 t = perf('gi_parse_nested', n, 'gi')
74 t = perf('nat_get_name', n, 'native')
75 t = perf('gi_get_name', n, 'gi')
78 t = perf('nat_get_value', n, 'native')
79 t = perf('gi_get_value', n, 'gi')