lvaruzza / cl-randist

Random number generation for common lisp
http://code.google.com/p/cl-randist/
20 stars 10 forks source link

Optimize JMT and RANDOM-NORMAL for SBCL #12

Closed kchanqvq closed 2 years ago

kchanqvq commented 2 years ago

I'm using random-normal in a tight simulation loop so I optimized its performance.

It gives 6x times speed up on my SBCL 2.1.11:

Before:

(time (loop for i below 1000000 sum (cl-randist:random-normal)))
Evaluation took:
0.619 seconds of real time
0.621047 seconds of total run time (0.615463 user, 0.005584 system)
[ Run times consist of 0.019 seconds GC time, and 0.603 seconds non-GC time. ]
100.32% CPU
1,977,362,915 processor cycles
406,634,128 bytes consed

-259.0154850085313d0

After:

(time (loop for i below 1000000 sum (cl-randist:random-normal)))
Evaluation took:
0.102 seconds of real time
0.102941 seconds of total run time (0.102102 user, 0.000839 system)
[ Run times consist of 0.005 seconds GC time, and 0.098 seconds non-GC time. ]
100.98% CPU
327,808,653 processor cycles
34,340,592 bytes consed

336.72073541129316d0

Future idea: RANDOM-NORMAL-ZIGGURAT sometimes uses JMT.LISP, sometimes uses system RANDOM (secretly in the call to RANDOM-POS and RANDOM-UNIFORM). Is it intentional? Would it be better if we consistently use (supposedly faster) JMT.LISP?

lvaruzza commented 2 years ago

Great,

Code merged.

Leo.