factor/library/test/benchmark/fac.factor

27 lines
492 B
Factor
Raw Normal View History

2004-08-25 20:51:19 -04:00
IN: scratchpad
USE: math
USE: test
2004-12-17 19:27:42 -05:00
USE: compiler
2005-01-06 23:16:13 -05:00
USE: kernel
2004-08-25 20:51:19 -04:00
2005-01-23 16:47:28 -05:00
: (fac) ( n! i -- n! )
dup 0 = [
drop
] [
[ * ] keep 1 - (fac)
] ifte ;
: fac ( n -- n! )
1 swap (fac) ;
2005-01-06 23:16:13 -05:00
: small-fac-benchmark
#! This tests fixnum math.
2005-01-23 16:47:28 -05:00
1 swap [ 10 fac 10 [ [ 1 + / ] keep ] repeat max ] times ; compiled
2005-01-06 23:16:13 -05:00
: big-fac-benchmark
2005-01-23 16:47:28 -05:00
10000 fac 10000 [ [ 1 + / ] keep ] repeat ; compiled
2004-12-17 19:27:42 -05:00
2005-01-06 23:16:13 -05:00
[ 1 ] [ big-fac-benchmark ] unit-test
[ 1 ] [ 1000000 small-fac-benchmark ] unit-test