countvajhula / countvajhula/seq
`nth` on vectors is slow
- Dominant language
- Racket
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
@sarna reports:
> ```
> (define len 100000)
> (define vec (vector->immutable-vector (make-vector len)))
>
> (collect-garbage)
> (collect-garbage)
> (collect-garbage)
>
> (displayln "vector-ref")
> (time (void (for/list ([i (in-range len)])
> (vector-ref vec i))))
>
> (collect-garbage)
> (collect-garbage)
> (collect-garbage)
>
> ; and so on and so forth
> ```
>
> gave me the following results on an m1 mac:
> ```
> vector-ref
> cpu time: 0 real time: 0 gc time: 0
> sequence-ref from racket/sequence
> cpu time: 39458 real time: 40506 gc time: 6
> nth from countvajhula's data/collection
> cpu time: 20 real time: 21 gc time: 2
> ref from countvajhula's data/collection
> cpu time: 37 real time: 38 gc time: 2
> nth from countvajhula's seq
> cpu time: 22136 real time: 23226 gc time: 5
> ```
>
And further:
```
vector-ref
cpu time: 0 real time: 0 gc time: 0
nth from lexilambda's data/collection
cpu time: 18 real time: 19 gc time: 1
nth from countvajhula's seq
cpu time: 21929 real time: 23028 gc time: 7
nth from countvajhula's seq pasted into the file
cpu time: 19 real time: 19 gc time: 1
```
> @countvajhula I think it's the contract https://github.com/countvajhula/seq/blob/c23829671293f1a7c40c9af367c24639c265093d/seq-lib/base.rkt#L33
Contributor guide
Assessment
This issue has not been assessed yet.