[TIL] hash-ref is very fast on hasheq

Laurent.O
Sun, 16 Oct 2022 17:25:39 +0000
General

Not a question per se, just a positive remark: I was wondering whether hash-ref was fast for fixed large sets of fixnums, or if a custom binary search could do better. Answer: It's plenty fast: it can answer 1 000 000 queries on a set of 10 000 000 fixnums in less than 200ms in total.

For reference:

gist.github.com

https://gist.github.com/Metaxal/97a9f582b0c84c8aa1c4aebeb77dc88e

hasheq-ref-vs-bin-search.rkt

#lang racket
(require racket/fixnum
         math/base)

;;; Conclusion: hasheq-ref is (slightly) faster than a custom binary search
;;; (It's actually probably implemented as a binary search, with some more optimization,
;;;  as the bin search is within a factor 2)

(#%declare #:unsafe)

This file has been truncated. show original

The custom binary search is actually slower, by a factor 2 or so.

At least I don't have to waste time on this, so thank you, implementors

6 posts - 6 participants