def measure_program(filename): in_filename = filename out_filename = filename[:-len(mp.mcode_suffix)]+mp.fit_suffix memory = simulate.initialize_memory(in_filename) ratios = fitness.main(memory) statistics = ratios #We create the file. tmp_tuple = tempfile.mkstemp(dir="/tmp/") tmp_fh = tmp_tuple[0] tmp_name = tmp_tuple[1] os.close(tmp_fh) fh = open(tmp_name, 'w') fh.write('\n'.join([str(i) for i in statistics])) fh.close() #I hope to god this cannot fail in-transit. Please please please be atomic. shutil.move(tmp_name, out_filename)
return collisions def multi_test(memory, ht, tests=fit_tests.tests): random.seed(fp.collision_seed) #Not strictly ratios; just single numbers #we are attempting to minimize ratios = [test(memory, ht, attempt) for test in tests] return [0] + ratios def main(memory, tests = fit_tests.tests): ht = {} try: ratios = multi_test(memory, ht, tests) return ratios except fit_tests.TrivialHashFunction: return [1.0] * len(tests) if __name__ == "__main__": in_filename = sys.argv[1] out_filename = sys.argv[2] memory = simulate.initialize_memory(in_filename) ratio = main(memory) fh = open(out_filename, 'w') fh.write(str(ratio)) fh.close()