Following my post a few days ago asking about which compilation settings to use for fastest throughput. I created a script that compiles the same file with different settings then uses hyperfine to check its performance. The first version (without parallelism) works just fine but is slow for testing 28 possible combinations. I tried to run it in parallel and now get this error
Error: cannot open 'C:\Users\youse\nimcache\main2_1_r\@m..@s..@s..@s..@s..@s..@s..@snim@slib@[email protected]
the last segment "ssyncio.nim.c" is not constant.
I tried copying the source file multiple times and compiling each copy only once, and tried deleting the nimcache multiple times
Is this error from nim? Or gcc? or the shell itself? I am using execCmdEx to run fmt"nim c {compileparams} {sourcenim}"
I will link the script in the reply
import std/[osproc,os],strformat,strutils,times,algorithm,threadpool #,sequtils
let starttime = cpuTime() type paramOpt = tuple[name,cmd: string]
#Get all possible combinations of compilation parameters
return a
basepoint = 0 inc length base = appendTuple(allparameters[basepoint..basepoint+length]) inc basepoint
var lastitem:paramOpt lastitem = appendTuple(allparameters) possibleCombos.add lastitem return possibleCombos
const possibleCombos = getpossibleCombos() const possibleComboslen= possibleCombos.len * 2
proc findmean(output: string): (float,string)= # proc findmean(output: string): string=
var lines = output.splitLines(false)
- for line in lines:
- if line.contains("mean"):
- var tmp1 = line.split(":")[1] var tmp2 = tmp1.splitWhitespace() var tmp3 = tmp2[1..4].join " " # return tmp2.join " " return (tmp2[0].parseFloat,tmp3)
#wrap execcmd,return stdout, and break on error
var res = execCmdEx(command)
return res
type Benchresult= tuple[time:(float,string),name: string] var benchSlice = newSeqOfCapBenchresult let benchdir = "bench" & format(times.now(),"yyyyMMdd-HHmm") os.createDir(benchdir) let sourcenim = os.paramStr(1).replace(".nim","") var res = sysexec(fmt"nim --hints:off c -r --o:{benchdir}base.exe {sourcenim}.nim") echo "base: ",res.output res = sysexec(fmt"hyperfine {benchdir}base.exe") benchSlice.add((res.output.findmean,"base")) discard execShellCmd("mkdir nimcopies >nul 2>&1")
setMaxPoolSize 4 var taskPromises = newSeqOfCapFlowvar[Benchresult] var nimcounter = 1
sync()
for task in taskPromises: benchSlice.add ^task benchSlice.sort(proc (a,b:Benchresult):int = cmp(a.time[0],b.time[0])) let benchmarkfile = benchdir & "\" & "benchmark.txt" var benchstr = benchSlice.join("n") benchstr.add("nBenchmarked " & $(possibleComboslen + 1) & " programs in " & $(cpuTime() - starttime) & "s") echo benchstr # echo "Benchmarked ", possibleCombos.len * 2 + 1, " programs in ", cpuTime() - starttime, "s" writeFile(benchmarkfile,benchstr)
Thanks! It works now
Even 2 threads in parallel affects the benchmark results a bit.
This experiment was not very fruitful