#!/usr/bin/env python3 import os import sys tune = { 'verify':('32',1), 'hashblocks':('8090',1), 'hash':('8090',1), 'dh_keypair':('32',1), 'dh':('32',3), 'sign_keypair':('32',1), 'sign':('59',3), 'sign_open':('59',10), } impls = set() data = {} def handle(benchmark): with open('benchmarks/%s' % benchmark) as f: for line in f: line = line.split() if line[:2] == ['lib25519','version']: version = line[2] continue if line[:2] == ['lib25519','arch']: arch = line[2] continue if line[:1] == ['cpuid']: cpuid = ''.join(line[1:]) if line[:3] == ['cpucycles','default','0']: cpucyclesoverhead = int(line[3]) if line[:3] == ['randombytes','default','26']: randombytesoverhead = int(line[3]) if len(line) >= 5: shortfun = line[0] if line[1].isnumeric() and line[2] == 'implementation' and line[4] == 'compiler': implnum = line[1] implo = line[0] i = line[3] c = ' '.join(line[5:]) if line[1].isnumeric() and shortfun in tune and line[2] == tune[shortfun][0] and line[3].isnumeric(): o = shortfun.split('_')[0] assert implo == o assert implnum == line[1] cycles = int(line[3]) cycles -= cpucyclesoverhead if shortfun.endswith('_keypair'): cycles -= randombytesoverhead if cycles < 1: cycles = 1 key = benchmark,version,arch,cpuid,o,i,c if key not in data: data[key] = [] data[key] += [(shortfun,cycles)] for benchmark in sorted(os.listdir('benchmarks')): handle(benchmark) impldata = {} bestscore = {} for key in sorted(data): benchmark,version,arch,cpuid,o,i,c = key assert sorted(shortfun for shortfun,cycles in data[key]) == sorted(shortfun for shortfun in tune if shortfun.split('_')[0] == o) score = sum(cycles*tune[shortfun][1] for shortfun,cycles in data[key]) if (o,i) not in impldata: impldata[o,i] = [] impldata[o,i] += [(benchmark,version,arch,cpuid,c,score)] if (benchmark,o) not in bestscore: bestscore[benchmark,o] = score bestscore[benchmark,o] = min(score,bestscore[benchmark,o]) os.makedirs('priority',exist_ok=True) for o,i in impldata: with open('priority/%s-%s' % (o,i),'w') as f: for benchmark,version,arch,cpuid,c,score in impldata[o,i]: if bestscore[benchmark,o] <= 0: continue f.write('%.6f %s %s %s %s %s %s\n' % (score/bestscore[benchmark,o],score,arch,cpuid,version,benchmark,c))