benchmark.memoize: adding a benchmark for memoization.

db4
John Benediktsson 2012-07-17 16:02:00 -07:00
parent cde26a3356
commit 72de9badda
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math memoize sequences ;
IN: benchmark.memoize
MEMO: mem1 ( n -- n ) 1 + ;
MEMO: mem2 ( n n -- n ) + ;
MEMO: mem3 ( n n n -- n ) + + ;
MEMO: mem4 ( n n n n -- n ) + + + ;
: memoize-benchmark ( -- )
1000 [
1000 iota [
[ mem1 ] keep [ mem2 ] 2keep [ mem3 ] 3keep mem4 drop
] each
] times ;
MAIN: memoize-benchmark