Created
January 10, 2017 10:19
-
-
Save ifduyue/987cfd1ae9cb1ec3447c08c738e324c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import threading | |
import xxhash | |
import os | |
import time | |
from itertools import repeat | |
def work(which, input, cycle): | |
x = getattr(xxhash, which)(input) | |
for i in repeat(None, cycle): | |
x.update(input) | |
return x.intdigest() | |
def test(which, thread_count, input_length, cycle): | |
input = os.urandom(input_length) | |
threads = [threading.Thread(target=work, args=(which, input, cycle))] | |
t1 = time.time() | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
t2 = time.time() | |
print(t2 - t1) | |
if __name__ == '__main__': | |
import sys | |
try: | |
which = sys.argv[1] | |
assert which in ('xxh32', 'xxh64') | |
thread_count, input_length, cycle = (int(i) for i in sys.argv[2:]) | |
except: | |
usage = 'Usage: {} [xxh32|xxh64] [thread-count] [input-length] [cycle]'.format(sys.argv[0]) | |
print(usage, file=sys.stderr) | |
sys.exit(1) | |
test(which, thread_count, input_length, cycle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment