Your "simpler" version can be made to work with a sequence (as Stefan said),
and actually using a tuple instead of an object (since they have comparison
operators defined):
import random
import algorithm
const
els = 10_000_000
maxval = 1_000_000
type E = tuple
r: int32
i: int32
proc main() =
var a = newSeq[E](els)
for i in 0..high(a):
a[i].r = int32(rand(maxval))
a[i].i = int32(i)
a.sort()
echo a[0..<5], " ... ", a[^5..^1]
main()
Run
- NvP: creating and sorting a large array of tuples HashBackupJim
- Re: NvP: creating and sorting a large array of tuples Stefan_Salewski
- Re: NvP: creating and sorting a large array of tu... Yardanico
- Re: NvP: creating and sorting a large array o... Yardanico
- Re: NvP: creating and sorting a large arr... HashBackupJim
- Re: NvP: creating and sorting a larg... HashBackupJim
- Re: NvP: creating and sorting a ... Yardanico
- Re: NvP: creating and sortin... HashBackupJim
- Re: NvP: creating and sortin... Stefan_Salewski
- Re: NvP: creating and sortin... doofenstein
- Re: NvP: creating and sortin... Stefan_Salewski
- Re: NvP: creating and sortin... doofenstein
