summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRune Halvorsen <runefh@gmail.com>2010-04-10 12:14:24 +0200
committerRune Halvorsen <runefh@gmail.com>2010-04-10 12:14:24 +0200
commitf6a3e5c60f83bf968fd4b23a51f33d5897601621 (patch)
tree8ee3ae0f418e9bae1de243d89c99b3b528f0a47b
parentc929cf5329e7a4a6d5b535b96c1e5a6b1394e7f4 (diff)
downloadanyjson-f6a3e5c60f83bf968fd4b23a51f33d5897601621.tar.gz
Added option to download real world data in benchmark.py
-rw-r--r--tests/benchmark.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/benchmark.py b/tests/benchmark.py
index e0c06fa..652f43b 100644
--- a/tests/benchmark.py
+++ b/tests/benchmark.py
@@ -4,6 +4,7 @@ Simple benchmark script to do some basic speed tests of json libs
import sys
import time
+import urllib
_small = """
{
@@ -69,6 +70,17 @@ _big = """
}
""" % locals()
+# The following two will contain real world json from twitter and reddit if
+# script is run with the --download flag
+_reddit = "[]"
+_twitter = "[]"
+
+def load_external_json():
+ global _reddit, _twitter
+ _reddit = urllib.urlopen("http://reddit.com/.json").read()
+ _twitter = urllib.urlopen("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitterapi&count=200").read()
+
+
def do_benchmark(impspec, json, runs=10):
modulename, funcname = impspec
@@ -100,18 +112,25 @@ modules = [("json", "loads"),
# ("demjson", "decode"), terribly slow. wont include it
]
+
+if len(sys.argv) > 1 and sys.argv[1] == "--download":
+ load_external_json()
+
res = []
runs = 100
for e in modules:
res.append((e[0], do_benchmark(e, _small, runs),
do_benchmark(e, _deep , runs),
- do_benchmark(e, _big, runs)))
+ do_benchmark(e, _big, runs),
+ do_benchmark(e, _reddit, runs),
+ do_benchmark(e, _twitter, runs),
+ ))
no_res = set([e for e in res if e[1] is None])
res = list(set(res) - no_res)
-res.sort(lambda a,b: cmp(sum(a[1:4]), sum(b[1:4])))
+res.sort(lambda a,b: cmp(sum(a[1:]), sum(b[1:])))
for e in res:
- print "%.3f %s" % (sum(e[1:4]), e[0])
+ print "%.3f %s" % (sum(e[1:]), e[0])
for e in no_res:
print "Not installed:", e[0]