**OderWat**,Thank you for editing the code :)

And it should be a little slower 
    
    
    import times
    import threadpool
    {.experimental.}
    
    var w = ["aaaaaaaaaa", "bbbbbbbbbb","cccccccccc"]
    
    var startTime = epochTime()
    parallel:
      for i,str in w:
        spawn writeFile("dict_" & $i & ".txt",enumerableRepeat(str, 3_000_000))
    
    echo "Time: ",epochTime() - startTime," seconds"
    #Time: 2.846011525369249 seconds
    

than this? 
    
    
    proc writeFile2(filePath,text:string) =
      var file = open(filePath,mode=fmWrite)
      for str in 1..3_000_000: file.writeLine(text)
      file.close()
    
    var w = ["aaaaaaaaaa", "bbbbbbbbbb","cccccccccc"]
    
    var startTime = epochTime()
    parallel:
      for i,str in w:
        spawn writeFile2("dict_" & $i & ".txt",str)
    
    echo "Time: ",epochTime() - startTime," seconds"
    #Time: 2.264008925878443 seconds
    

PS: I wanted to do something like how in C # 
    
    
    Parallel.For(0, 3,  i=> {File.WriteAllLines(@"dict" + i + 
".txt",Enumerable.Repeat(w[i],3000000));});

But there is a running total 00:00:01.1200015

Reply via email to