Skip to content

Commit

Permalink
Updates for the write-100mb benchmark
Browse files Browse the repository at this point in the history
* Add a Racket implementation.
* Add README.rst with current results on my machine and a note about Unicode.
* Write 100x more data to get a stronger signal and amortize startup costs.  I
  want to run these all as executables so I can do the timing the same way, with
  the `time` command. Dylan has faster startup times, so we could argue whether
  that's fair, but we'll worry about that when Dylan's times get good enough for
  that to matter.
  • Loading branch information
cgay committed May 31, 2024
1 parent f546cf1 commit ac66d23
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
14 changes: 14 additions & 0 deletions sources/testing/benchmarks/write-100mb/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Write 10_000MB, best of three runs on an Apple M3 Pro, May 2024:

Python SBCL Dylan Racket
real 7.500s 13.837s 23.425s 30.620s
1.0x 1.8x 3.1x 4.1x
user 4.837s 11.334s 6.455s 21.053s
1.0x 2.3x 1.3x 4.4x
sys 2.286s 2.368s 10.749s 7.031s


Note that the other implementations are using Unicode so comparison isn't
really fair. In particular, Racket does better than SBCL if the test is changed
to use a byte string (#"xxx") but has a particularly pessimized Unicode path,
it seems.
9 changes: 6 additions & 3 deletions sources/testing/benchmarks/write-100mb/write-100mb.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ Module: write-100mb
define function main
()
let string = make(<string>, size: 100, fill: 'x');
with-open-file (stream = "/tmp/100mb.dylan.txt", direction: #"output")
for (i from 1 to 1024 * 1024)
write(stream, string);
for (o from 1 to 100)
with-open-file (stream = "/tmp/100mb.dylan.txt",
direction: #"output")
for (i from 1 to 1024 * 1024)
write(stream, string);
end;
end;
end;
end function;
Expand Down
12 changes: 7 additions & 5 deletions sources/testing/benchmarks/write-100mb/write-100mb.lisp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
(in-package :cl-user)

(defun write-100mb ()
(defun write-10000mb ()
;; (declare (optimize (speed 3) (debug 0)))
(let ((string (make-string 100 :initial-element #\x)))
(with-open-file (stream "/tmp/100mb.sbcl.txt" :direction :output :if-exists :supersede)
(loop repeat (* 1024 1024)
do (write-string string stream)))))
(loop repeat 100
do (with-open-file (stream "/tmp/100mb.sbcl.txt" :direction :output :if-exists :supersede)
(loop repeat (* 1024 1024)
do (write-string string stream))))))

(write-100mb)
;;; sbcl --noinform --no-sysinit --no-userinit --eval '(load "write-100mb.lisp")' --eval '(sb-ext:save-lisp-and-die #P"/tmp/clwrite100mb" :executable t :toplevel 'cl-user::write-10000mb)'
20 changes: 20 additions & 0 deletions sources/testing/benchmarks/write-100mb/write-100mb.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#lang racket/base

(require racket/port)

(define (write-10000mb)
;; Use #"xxx" to write a byte string instead. MUCH faster.
(let ((string "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
(let outer ((o 100))
(when (> o 0)
(call-with-output-file
#:exists 'truncate
"/tmp/100mb.racket.txt"
(lambda (port)
(let loop ((n (* 1024 1024)))
(when (> n 0)
(display string port)
(loop (- n 1))))))
(outer (- o 1))))))

(write-10000mb)
7 changes: 4 additions & 3 deletions sources/testing/benchmarks/write-100mb/write_100mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

def main ():
s = "x" * 100
with open("/tmp/100mb.python.txt", "w") as fd:
for i in range(1024 * 1024):
fd.write(s)
for x in range(100):
with open("/tmp/100mb.python.txt", "w") as fd:
for i in range(1024 * 1024):
fd.write(s)

if __name__ == "__main__":
main()

0 comments on commit ac66d23

Please sign in to comment.