ffi-overhead
ffi-overhead copied to clipboard
suggest adding a python version
Python is another language which commonly calls into C functions.
Anyone want to have a crack at it? (PR)
@dyu Don't actually want to make PR, because I don't want to install all the dependencies to make clean test before submitting it :blush: But code would be something like this:
import sys
from ctypes import cdll
lib = cdll.LoadLibrary("newplus/libplus.so")
def run(count):
start = lib.current_timestamp()
x = 0
while x < count:
x = lib.plusone(x)
print(lib.current_timestamp() - start)
def main():
if len(sys.argv) == 1:
print("First arg (0 - 2000000000) is required.")
return
try:
count = int(sys.argv[1])
if count <= 0 or count > 2000000000:
raise ValueError
except ValueError:
print("Must be a positive number not exceeding 2 billion.")
return
run(count)
if __name__ == '__main__':
main()