Skip to content

Instantly share code, notes, and snippets.

@lojic
Last active December 16, 2021 13:57
Show Gist options
  • Save lojic/78cc5c89e0080331f487e2db9c44dc47 to your computer and use it in GitHub Desktop.
Save lojic/78cc5c89e0080331f487e2db9c44dc47 to your computer and use it in GitHub Desktop.
#lang racket
(require data/heap)
(define input (for/list ([ _ (in-range 115000) ])
(random-string 15)))
(define (with-heap)
(define obj (make-heap string<?))
(for ([ s (in-list input) ])
(heap-add! obj s))
(heap-min obj))
(define (with-sort)
(let loop ([ input input ][ result '() ])
(if (null? input)
(car result)
(loop (cdr input)
(sort (cons (car input) result)
string<?)))))
(define (with-insertion)
(define (insert s lst)
(cond [ (null? lst)
(cons s lst) ]
[ (string<? s (car lst))
(cons s lst) ]
[ else
(cons (car lst) (insert s (cdr lst))) ]))
(let loop ([ strs input ]
[ result '() ])
(if (null? strs)
(car result)
(loop (cdr strs) (insert (car strs) result)))))
(time (with-heap))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment