From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Amirouche Boubekki Newsgroups: gmane.lisp.guile.user Subject: Custom streams 10x faster than srfi-41 Date: Mon, 05 Sep 2016 19:24:37 +0200 Message-ID: <27b5ca31bf05c1a68615f079cf5276ea@hypermove.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_f0ce9424b38ca4ea6ae8d7c0a1ff6f5a" X-Trace: blaine.gmane.org 1473096477 18662 195.159.176.226 (5 Sep 2016 17:27:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Sep 2016 17:27:57 +0000 (UTC) User-Agent: Roundcube Webmail/1.1.2 To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Sep 05 19:27:53 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bgxgW-0004GU-Tl for guile-user@m.gmane.org; Mon, 05 Sep 2016 19:27:53 +0200 Original-Received: from localhost ([::1]:55979 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgxgU-0007dR-Ao for guile-user@m.gmane.org; Mon, 05 Sep 2016 13:27:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgxdV-0005tO-1X for guile-user@gnu.org; Mon, 05 Sep 2016 13:24:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgxdR-0006o4-PU for guile-user@gnu.org; Mon, 05 Sep 2016 13:24:44 -0400 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:43868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgxdR-0006nN-II for guile-user@gnu.org; Mon, 05 Sep 2016 13:24:41 -0400 Original-Received: from mfilter31-d.gandi.net (mfilter31-d.gandi.net [217.70.178.162]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 13B89A80E1 for ; Mon, 5 Sep 2016 19:24:39 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter31-d.gandi.net Original-Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter31-d.gandi.net (mfilter31-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id f0RnSpPX85XP for ; Mon, 5 Sep 2016 19:24:37 +0200 (CEST) X-Originating-IP: 10.58.1.147 Original-Received: from webmail.gandi.net (webmail7-d.mgt.gandi.net [10.58.1.147]) (Authenticated sender: amirouche@hypermove.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPA id 3AFCBA80CD for ; Mon, 5 Sep 2016 19:24:37 +0200 (CEST) X-Sender: amirouche@hypermove.net X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.70.183.195 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:12877 Archived-At: --=_f0ce9424b38ca4ea6ae8d7c0a1ff6f5a Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed 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 --=_f0ce9424b38ca4ea6ae8d7c0a1ff6f5a Content-Transfer-Encoding: base64 Content-Type: text/plain; name=traversi-benchmark.scm Content-Disposition: attachment; filename=traversi-benchmark.scm; size=1771 KHVzZS1tb2R1bGVzIChzcmZpIHNyZmktNDEpKQoodXNlLW1vZHVsZXMgKGljZS05IG1hdGNoKSkK KHVzZS1tb2R1bGVzIChzcmZpIHNyZmktOSkpICA7OyByZWNvcmRzCih1c2UtbW9kdWxlcyAoc3Jm aSBzcmZpLTkgZ251KSkgIDs7IHNldC1yZWNvcmQtdHlwZS1wcmludGVyISBhbmQgc2V0LWZpZWxk CgoKKGRlZmluZSAobGlzdC0+dHJhdmVyc2kgbHN0KQogIChsZXQgbG9vcCAoKGxzdCBsc3QpKQog ICAgKGxhbWJkYSAoKQogICAgICAoaWYgKG51bGw/IGxzdCkKICAgICAgICAgICcoKQogICAgICAg ICAgKGNvbnMgKGNvbnMgKGNhciBsc3QpICcoKSkgKGxvb3AgKGNkciBsc3QpKSkpKSkpCgooZGVm aW5lICh0cmF2ZXJzaS0+bGlzdCB0cmF2ZXJzaSkKICAobGV0IGxvb3AgKCh0cmF2ZXJzaSB0cmF2 ZXJzaSkKICAgICAgICAgICAgIChvdXQgJygpKSkKICAgIChtYXRjaCAodHJhdmVyc2kpCiAgICAg ICgnKCkgKHJldmVyc2Ugb3V0KSkKICAgICAgKChpdGVtIC4gbmV4dCkgKGxvb3AgbmV4dCAoY29u cyAoY2FyIGl0ZW0pIG91dCkpKSkpKQoKKGRlZmluZSAodHJhdmVyc2ktbWFwIHByb2MgdHJhdmVy c2kpCiAgKGxldCBsb29wICgodHJhdmVyc2kgdHJhdmVyc2kpKQogICAgKGxhbWJkYSAoKQogICAg ICAobWF0Y2ggKHRyYXZlcnNpKQogICAgICAgICgnKCkgJygpKQogICAgICAgICgoaXRlbSAuIG5l eHQpIChjb25zIChjb25zIChwcm9jIChjYXIgaXRlbSkpIGl0ZW0pIChsb29wIG5leHQpKSkpKSkp CgooZGVmaW5lICh0cmF2ZXJzaS1maWx0ZXIgcHJvYyB0cmF2ZXJzaSkKICAobGV0IGxvb3AxICgo dHJhdmVyc2kgdHJhdmVyc2kpKQogICAgKGxhbWJkYSAoKQogICAgICAobGV0IGxvb3AyICgodHJh dmVyc2kgdHJhdmVyc2kpKQogICAgICAgIChtYXRjaCAodHJhdmVyc2kpCiAgICAgICAgICAoJygp ICcoKSkKICAgICAgICAgICgoaXRlbSAuIG5leHQpIChpZiAocHJvYyAoY2FyIGl0ZW0pKQogICAg ICAgICAgICAgICAgICAgICAgICAgICAgIChjb25zIGl0ZW0gKGxvb3AxIG5leHQpKQogICAgICAg ICAgICAgICAgICAgICAgICAgICAgIChsb29wMiBuZXh0KSkpKSkpKSkKCihkZWZpbmUgKHRyYXZl cnNpLXBhcmVudCB0cmF2ZXJzaSkKICAobGV0IGxvb3AgKCh0cmF2ZXJzaSB0cmF2ZXJzaSkpCiAg ICAobGFtYmRhICgpCiAgICAgIChtYXRjaCAodHJhdmVyc2kpCiAgICAgICAgKCcoKSAnKCkpCiAg ICAgICAgKChpdGVtIC4gbmV4dCkKICAgICAgICAgKGxldCAoKHBhcmVudHMgKGNkciBpdGVtKSkp CiAgICAgICAgICAgKGlmIChudWxsPyBwYXJlbnRzKQogICAgICAgICAgICAgICAodGhyb3cgJ3Ry YXZlcnNpICJpdGVtIGhhcyBubyBwYXJlbnQiKQogICAgICAgICAgICAgICAoY29ucyBwYXJlbnRz IChsb29wIG5leHQpKSkpKSkpKSkKCihkZWZpbmUtc3ludGF4LXJ1bGUgKHRpbWVpdCBib2R5IC4u LikKICAobGV0ICgoc3RhcnQgKGN1cnJlbnQtdGltZSkpKQogICAgKGJlZ2luIGJvZHkgLi4uKQog ICAgKC0gKGN1cnJlbnQtdGltZSkgc3RhcnQpKSkKCihkZWZpbmUgY291bnQgMTAwMDAwMDApCgoo cGsgKHRpbWVpdCAodHJhdmVyc2ktPmxpc3QgKHRyYXZlcnNpLWZpbHRlciBvZGQ/ICh0cmF2ZXJz aS1tYXAgKGxhbWJkYSAoeCkgKCogMyB4KSkgKGxpc3QtPnRyYXZlcnNpIChpb3RhIGNvdW50KSkp KSkpKQoKKHBrICh0aW1laXQgKHN0cmVhbS0+bGlzdCAoc3RyZWFtLWZpbHRlciBvZGQ/IChzdHJl YW0tbWFwIChsYW1iZGEgKHgpICgqIDMgeCkpIChsaXN0LT5zdHJlYW0gKGlvdGEgY291bnQpKSkp KSkpCg== --=_f0ce9424b38ca4ea6ae8d7c0a1ff6f5a--