File: screedTimeit1M.py

package info (click to toggle)
python-screed 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 820 kB
  • sloc: python: 3,356; makefile: 169; sh: 32; javascript: 16
file content (41 lines) | stat: -rwxr-xr-x 931 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# Copyright (c) 2016, The Regents of the University of California.

import timeit
import sys
import os

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print "Usage: %s <filename>" % sys.argv[0]
        exit(1)

    screedFile = sys.argv[1]
    if not os.path.isfile(screedFile):
        print "No such file: %s" % screedFile
        exit(1)

    runStatement = """
for i in xrange(0, 100000):
    entry = str(db[random.choice(keys)].sequence)
"""

    setupStatement = """
import os, sys
import random
thisdir = sys.path[0]
libdir = os.path.abspath(os.path.join(thisdir, '..'))
sys.path.insert(0, libdir)
import screed
db = screed.openscreed.ScreedDB('%s')
keys = []
for i, k in enumerate(db.iterkeys()):
    if i > 1000000:
        break
    keys.append(k)
""" % screedFile

    t = timeit.Timer(runStatement, setupStatement)

    print "[SCREED RUN]%s:" % screedFile
    print t.repeat(2, 1)