diff --git a/benchmarks/parameters.py b/benchmarks/parameters.py new file mode 100644 index 0000000..9098fde --- /dev/null +++ b/benchmarks/parameters.py @@ -0,0 +1,44 @@ +""" +Compare passing a dict to passing a dict as kwargs to a stupid transformation + +Last results (1 mill calls): + +j1 1.5026444319955772 +k1 1.8377482700016117 +j2 1.1962292949901894 +k2 1.5545833489886718 +j3 1.0014333260041894 +k3 1.353256585993222 + +""" +import json +import timeit + +def j1(d): + return {'prepend': 'foo', **d, 'append': 'bar'} + +def k1(**d): + return {'prepend': 'foo', **d, 'append': 'bar'} + +def j2(d): + return {**d} + +def k2(**d): + return {**d} + +def j3(d): + return None + +def k3(**d): + return None + +if __name__ == '__main__': + import timeit + + with open('person.json') as f: + json_data = json.load(f) + + + for i in 1,2,3: + print('j{}'.format(i), timeit.timeit("j{}({!r})".format(i, json_data), setup="from __main__ import j{}".format(i))) + print('k{}'.format(i), timeit.timeit("k{}(**{!r})".format(i, json_data), setup="from __main__ import k{}".format(i))) diff --git a/benchmarks/person.json b/benchmarks/person.json new file mode 100644 index 0000000..2bd2886 --- /dev/null +++ b/benchmarks/person.json @@ -0,0 +1,46 @@ +{ + "@context": "http://schema.org", + "@type": "MusicEvent", + "location": { + "@type": "MusicVenue", + "name": "Chicago Symphony Center", + "address": "220 S. Michigan Ave, Chicago, Illinois, USA" + }, + "name": "Shostakovich Leningrad", + "offers": { + "@type": "Offer", + "url": "/examples/ticket/12341234", + "price": "40", + "priceCurrency": "USD", + "availability": "http://schema.org/InStock" + }, + "performer": [ + { + "@type": "MusicGroup", + "name": "Chicago Symphony Orchestra", + "sameAs": [ + "http://cso.org/", + "http://en.wikipedia.org/wiki/Chicago_Symphony_Orchestra" + ] + }, + { + "@type": "Person", + "image": "/examples/jvanzweden_s.jpg", + "name": "Jaap van Zweden", + "sameAs": "http://www.jaapvanzweden.com/" + } + ], + "startDate": "2014-05-23T20:00", + "workPerformed": [ + { + "@type": "CreativeWork", + "name": "Britten Four Sea Interludes and Passacaglia from Peter Grimes", + "sameAs": "http://en.wikipedia.org/wiki/Peter_Grimes" + }, + { + "@type": "CreativeWork", + "name": "Shostakovich Symphony No. 7 (Leningrad)", + "sameAs": "http://en.wikipedia.org/wiki/Symphony_No._7_(Shostakovich)" + } + ] +}