Untitled
unknown
python
a year ago
2.2 kB
7
Indexable
import subprocess import re N = 10 NUM_PROCEESS = 1000 HIGH = 0.7 LOW = 0.2 names = ["Wachtijd op geheugen", "Eerste CPU", 'Executie vanaf geheugen', 'Totale tijd'] def parseOutput(lines): lines = lines[lines.index('', lines.index( '', lines.index('') + 1) + 1) + 1:] all_values = list() for _ in range(4): values = list() for line in lines[:2]: for s in re.findall(r"[-+]?\d*\.\d+|\d+", line): values.append(float(s)) all_values.append(values) lines = lines[lines.index('') + 1:] lines = lines[lines.index('') + 1:] return all_values def runProgram(program, cpu, io, memory): prog = subprocess.Popen( ['./'+program, '-c ' + str(cpu), '-i '+str(io), '-m '+str(memory), '-p '+str(NUM_PROCEESS)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) out, err = prog.communicate() return parseOutput((out).split("\n")) def getAverage(program, cpu, io, memory): hmmm = [[] for _ in range(4)] for _ in range(N): res = runProgram(program, cpu, io, memory) for j, lst in enumerate(res): hmmm[j].append(lst[0]) return list(map(lambda x: round(sum(x)/len(x)), hmmm)) def printStats(name, cpu, io, memory): print(f"STATS FOR: {name} == c={cpu}, io={io}, mem={memory}") print("Memory: ", list(zip(getAverage("memory", cpu, io, memory), names))) print("Roundrobin: ", list( zip(getAverage("roundrobin", cpu, io, memory), names))) print("Fast: ", list(zip(getAverage("fast", cpu, io, memory), names))) print() print( f"TOTAL STATS ARE AVERAGED OVER N={N} runs with {NUM_PROCEESS} processes") allStats = [ ("High CPU, low MEM, low IO", HIGH, LOW, LOW), ("High CPU, high MEM, low IO", HIGH, LOW, HIGH), ("High CPU, low MEM, high IO", HIGH, HIGH, LOW), ("High CPU, high MEM, high IO", HIGH, HIGH, HIGH), # We write CPU schedulers, so these results are worthless ("Low CPU, low MEM", LOW, 0.5, LOW), ("Low CPU, high MEM", LOW, 0.5, HIGH), ] for (x, y, z, w) in allStats: printStats(x, y, z, w)
Editor is loading...
Leave a Comment