wrap.py (521B)
1 import ctypes 2 import sys 3 import time 4 5 libkeccak = ctypes.CDLL('libkeccaktiny.so') 6 7 buf = ctypes.pointer((ctypes.c_char * 256)()) 8 data = ctypes.create_string_buffer(b'foo') 9 10 for i in range(10000): 11 libkeccak.hash(buf, 32, data, 3, 200-64, 1) 12 13 start_time = time.clock_gettime_ns(time.CLOCK_PROCESS_CPUTIME_ID) 14 for i in range(100000): 15 libkeccak.hash(buf, 32, data, 3, 200-64, 1) 16 end_time = time.clock_gettime_ns(time.CLOCK_PROCESS_CPUTIME_ID) 17 18 print((end_time - start_time) / (10**9)) 19 print(buf.contents.value.hex())