Commits

Rune Halvorsen committed e176f9e

Added option to download real world data in benchmark.py

  • Participants
  • Parent commits 07388e9

Comments (0)

Files changed (1)

tests/benchmark.py

 
 import sys
 import time
+import urllib
 
 _small = """
 {
 }
 """ % 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
 
        #    ("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]