>>100192796
(defun random-array (size)
(let ((array (make-array (list size size size) :element-type '(unsigned-byte 8))))
(loop for i from 0 below (* size size size)
do (setf (row-major-aref array i) (random 3)))))
Λ> (time (random-array 256))
Evaluation took:
0.687 seconds of real time
0.686220 seconds of total run time (0.678617 user, 0.007603 system)
99.85% CPU
951,753,096 processor cycles
16,777,232 bytes consed
Seems like most time is just spent on the 'random call. Apparently that is not very optimized in SBCL (calling ironclad:crypto * 256 256 256 is about 5 times faster):
(time (crypto:random-data (* 256 256 256)))
Evaluation took:
0.099 seconds of real time
0.100386 seconds of total run time (0.004359 user, 0.096027 system)
101.01% CPU
138,878,826 processor cycles
16,777,232 bytes consed
If the Rust stuff is much faster it's probably doing vectorization or something, possibly with the hardware x86 RNG (SBCL only uses its own MT19937 random generator as RANDOM takes an optional STATE argument) which I presume is somewhat faster.
Luckily you'd want some noise function for terrain generation, not the #'random function, so this shouldn't matter too much I think.
Also, fastest random function I found on my Lisp image was this:
(time (cl+ssl:random-bytes (* 256 256 256)))
Evaluation took:
0.015 seconds of real time
0.018230 seconds of total run time (0.018098 user, 0.000132 system)
120.00% CPU
25,191,446 processor cycles
33,554,464 bytes consed
which just uses the OpenSSL random number generation.