$ ./test
34000000000 17.1602475643158s 17.081380504s
34000000000 0.455101490020752s 0.450769932s
$ cat test.nim
import std/[os, times, parseopt, strformat]
var s = @"abcdefg"
s[1..5] = @"ac"
assert s == @"aacg"
template `time`*(body: typed): auto =
block:
let
t0 = epochTime()
t1 = cpuTime()
body
(epochTime()-t0, cpuTime()-t1)
s = @"1234567890abcdefghjklmnopqrstuvwxyz"
let n: int = 1000000000
var sum: int = 0
var (real, cpu) = time:
for i in 0 ..< n:
for j in s[1 .. ^1]:
sum += 1
echo(fmt"{sum} {real}s {cpu}s")
sum = 0
(real, cpu) = time:
for i in 0 ..< n:
for j in 1 ..< s.len:
sum += 1
echo(fmt"{sum} {real}s {cpu}s")
This link is a bit confusing. @ElegantBeef refers to his library 'slicerator', and here's a github page: https://github.com/beef331/slicerator
You can install it with nimble install slicerator.