The first version of factorial in SBCL takes less time and processor cycle,
CL-USER> (time (fact 5))
Evaluation took:
0.000 seconds of real time
0.000002 seconds of total run time (0.000001 user, 0.000001 system)
100.00% CPU
1,550 processor cycles
0 bytes consed
120
compared to second version of factorial CL-USER> (time (fact2 5))
Evaluation took:
0.000 seconds of real time
0.000027 seconds of total run time (0.000027 user, 0.000000 system)
100.00% CPU
64,240 processor cycles
0 bytes consed
120
How it works for other lisp implementation. However when I reach for bigger number things looks different. CL-USER> (time (fact 10000))
Evaluation took:
0.044 seconds of real time
0.045335 seconds of total run time (0.036745 user, 0.008590 system)
[ Run times consist of 0.021 seconds GC time, and 0.025 seconds non-GC time. ]
102.27% CPU
111,336,538 processor cycles
69,739,552 bytes consed
CL-USER> (time (fact2 10000))
Evaluation took:
0.021 seconds of real time
0.021083 seconds of total run time (0.020312 user, 0.000771 system)
[ Run times consist of 0.003 seconds GC time, and 0.019 seconds non-GC time. ]
100.00% CPU
51,983,719 processor cycles
78,751,760 bytes consed
I wonder some kind of compiler magic kicks in, for higher number.