I tried to compare string concatenation using ropes and system's add, but seems 
the bench mark result is not right... Does anyone know how to use this module 
efficiently? (Also, I must admit that I never used rope algorithm, so I might 
doing wrong)

rope_test.nim 
    
    
    import times, ropes
    
    proc strBench(sample: Rope|string) =
      var str = when sample is Rope: rope("") else: ""
      
      let startTime = getTime()
      defer:
        let endTime = getTime()
        echo endTime.toSeconds() - startTime.toSeconds()
      
      for i in 0 .. 6_000_000:
        str.add sample
    
    
    const sample = "something\n"
    strBench(sample.rope())
    strBench(sample)
    
    # nim c -r rope_test.nim
    #   rope version -> 3 sec
    #   normal version -> 1 sec
    
    

Reply via email to