unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* SHA256 performance with Guile 2.2 vs. Guile 3.0
@ 2020-01-03 23:55 Ludovic Courtès
  2020-01-04  0:40 ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2020-01-03 23:55 UTC (permalink / raw)
  To: Guile Devel; +Cc: Andy Wingo

[-- Attachment #1: Type: text/plain, Size: 1640 bytes --]

Hello Guilers!

Göran Weinholt wrote a pure-Scheme (R6RS) implementation of common
cryptographic hash functions:

  https://github.com/weinholt/hashing

I thought this would make a useful benchmark (and probably favorable to
JIT because it’s one hot loop), so here goes (computing the SHA256 hash
of ‘guile-2.2.6.tar.xz’ with the code below, compiled with -O2, Guile
2.2.6 vs. 2.9.8):

--8<---------------cut here---------------start------------->8---
ludo@ribbon ~/src/guix$ ./pre-inst-env guix environment --pure --ad-hoc guile guile-hashing -- guile ~/tmp/sha256.scm

;;; (hash "b33576331465a60b003573541bf3b1c205936a16c407bc69f8419a527bf5c988")
clock utime stime cutime cstime gctime
135.07 164.13  0.52   0.00   0.00  42.14
ludo@ribbon ~/src/guix$ ./pre-inst-env guix environment --pure --ad-hoc guile-next guile3.0-hashing -- guile ~/tmp/sha256.scm

;;; (hash "b33576331465a60b003573541bf3b1c205936a16c407bc69f8419a527bf5c988")
clock utime stime cutime cstime gctime
65.17 89.75  0.45   0.00   0.00  35.63
--8<---------------cut here---------------end--------------->8---

Guile 3 is twice as fast!  No difference if we force ‘-O3’.

Still far from the libgcrypt implementation in C + asm, but hey!

--8<---------------cut here---------------start------------->8---
ludo@ribbon ~/src/guix$ time guix hash -f hex "/gnu/store/zfp7d4wr5hbl5lrnzs8c15bsc3ygq74g-guile-2.2.6.tar.xz"
b33576331465a60b003573541bf3b1c205936a16c407bc69f8419a527bf5c988

real	0m0.097s
user	0m0.093s
sys	0m0.024s
--8<---------------cut here---------------end--------------->8---

To be continued…

Ludo’.


[-- Attachment #2: The code --]
[-- Type: text/plain, Size: 756 bytes --]

(use-modules (hashing sha-2)
             (rnrs bytevectors)
             (ice-9 binary-ports)
             (ice-9 match)
             (ice-9 time))

(define (port-sha256 port)
  ;; Return the SHA256 of the data read from PORT.
  (define bv (make-bytevector 65536))
  (define hash (make-sha-256))

  (let loop ()
    (match (get-bytevector-n! port bv 0
                              (bytevector-length bv))
      ((? eof-object?)
       (sha-256-finish! hash)
       hash)
      (n
       (sha-256-update! hash bv 0 n)
       (loop)))))

(define (file-sha256 file)
  ;; Return the SHA256 of FILE.
  (call-with-input-file file port-sha256))

(time (pk 'hash (sha-256->string (file-sha256 "/gnu/store/zfp7d4wr5hbl5lrnzs8c15bsc3ygq74g-guile-2.2.6.tar.xz"))))

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-01-07 22:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-03 23:55 SHA256 performance with Guile 2.2 vs. Guile 3.0 Ludovic Courtès
2020-01-04  0:40 ` Ludovic Courtès
2020-01-04 10:28   ` Göran Weinholt
2020-01-04 15:51     ` Nala Ginrut
2020-01-04 21:39     ` Arne Babenhauserheide
2020-01-05 14:28       ` Göran Weinholt
2020-01-06  9:37     ` Ludovic Courtès
2020-01-05  9:48   ` Andy Wingo
2020-01-06  9:47     ` Ludovic Courtès
2020-01-06 19:52       ` Andy Wingo
2020-01-07 11:08         ` Ludovic Courtès
2020-01-07 21:45           ` Andy Wingo
2020-01-07 22:59             ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).