Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_benchmarks(N, size):
timings = {}
nframes = compute_nframes(N, size);
actual_size = compute_actual_size(N, nframes);
# first, write the file and time how long it takes
print("Writing file: ", file=sys.stderr)
start = time.time();
gsd.libgsd.gsd_create('test.gsd', 'test', 'test', 1);
file = gsd.libgsd.gsd_open('test.gsd');
write_random_file(file, nframes, N);
gsd.libgsd.gsd_close(file);
end = time.time();
timings['write'] = actual_size / 1024**2 / (end - start);
call(['sudo', '/bin/sync']);
call(['sudo', '/sbin/sysctl', 'vm.drop_caches=3'], stdout=PIPE);
# time how long it takes to open the file
print("Opening file... ", file=sys.stderr, end='')
start = time.time();
file = gsd.libgsd.gsd_open('test.gsd');
end = time.time();
print(end - start, "s", file=sys.stderr);
timings['open_time'] = (end - start);
end = time.time();
timings['seq_cache_read'] = actual_size / 1024**2 / (end - start);
else:
timings['seq_cache_read'] = 0;
# Read the file randomly and measure the time taken
print("Random read file:", file=sys.stderr)
start = time.time();
read_random_file(file, nframes, N);
end = time.time();
timings['random_read'] = actual_size / 1024**2 / (end - start);
timings['random_read_time'] = (end - start) / nframes / 1e-3;
gsd.libgsd.gsd_close(file);
os.unlink('test.gsd')
return timings