guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom streams 10x faster than srfi-41


From: Amirouche Boubekki
Subject: Custom streams 10x faster than srfi-41
Date: Mon, 05 Sep 2016 19:24:37 +0200
User-agent: Roundcube Webmail/1.1.2

Yesterday I discovered that my custom stream library is 10 times
faster than srfi-41 on guile 2.1.3

Basically, this custom stream thing is based on delayed lambda
evaluation or something like that. Since code is better than
a hundred word, here is a lazy version of `iota':

(define (lazy-iota count)
  (let loop ((i 0))
    (lambda ()
      (unless (eq? i count)
        (cons i (loop (1+ i)))))))

(define iota3 (lazy-iota 3))

(pk (iota3))

The first time `lazy-iota' is called it returns a procedure
that is bound to `count'. Then you can call that procedure
to get a pair with the first value and a procedure which will
allow to retrieve the rest.

I attached a file that mimicks Tinkerpop's Gremlin DSL and
benchmark it against srfi 41.


Happy hacking!

--
Amirouche ~ amz3 ~ http://www.hyperdev.fr

Attachment: traversi-benchmark.scm
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]