Found that use of iterator which just extend field is cost additional
computation time (about 20% time more)
nim
import std/[json, times, monotimes, tables]
let a = %*{"a": 1, "b": 2, "c": 3}
var start = getMonoTime()
for i in 1..1_000_000:
for k, v in a.fields.pairs:
discard
echo getMonoTime()-start
start = getMonoTime()
for i in 1..1_000_000:
for k, v in a.pairs:
discard
echo getMonoTime()-start
Run
but i dont see such effect when trying to simplify case
iterator q1(): int =
for i in 1..1_000_000:
yield i
iterator q2(): int =
for i in q1():
yield i
var start = getMonoTime()
for i in q1():
discard
echo getMonoTime()-start
start = getMonoTime()
for i in q2():
discard
echo getMonoTime()-start
Run