I did some more work on it, I measured time at each array size from 0 to
10_000, see chart:
[https://dl3.pushbulletusercontent.com/4m74W8NlcdcrpJnVgCT53RkL2nxUPimc/image.png](https://dl3.pushbulletusercontent.com/4m74W8NlcdcrpJnVgCT53RkL2nxUPimc/image.png)
It shows you how much tables are faster during each number of elements.
run with nim c -r --d:danger
import times
import tables
import random
var myTable = initTable[int, int]()
var myList: seq[int]
for i in 0 .. 1_000:
myTable[i] = i
myList.add(i)
myList.shuffle()
var dummyCounter = 0
for n in 0 .. 10_000:
const trytimes = 10
var start = epochTime()
for j in 0 .. trytimes:
for i in 0 ..< n:
if myList.contains(i):
inc dummyCounter
let listTime = epochTime() - start
start = epochTime()
for j in 0 .. trytimes:
for i in 0 ..< n:
if myTable.hasKey(i):
inc dummyCounter
let tableTime = epochTime() - start
echo n, ", ", listTime/trytimes, ", ", tableTime/trytimes
echo dummyCounter
Run