# Pastebin MUsu3a88 import time from _strlen import ffi, lib t0 = time.time() l = [b"x", b"y"] b_s = b"foo" for i in range(10000000): s = b_s + l[i % 2] lib.strlen(s) t1 = time.time() print("Direct bytes: %.2f" % (t1 - t0)) for i in range(10000000): s = b_s + l[i % 2] lib.strlen(ffi.from_buffer(memoryview(s))) t2 = time.time() print("from_buffer(memoryview(bytes)): %.2f" % (t2 - t1)) for i in range(10000000): s = b_s + l[i % 2] lib.strlen(ffi.from_buffer(s)) t3 = time.time() print("from_buffer(bytes): %.2f" % (t3 - t2))