Paste: type inference

Author: jon
Mode: factor
Date: Sun, 20 Jan 2013 01:04:38
Plain Text |
USING: formatting typed ;
1000000 0 <array>
: my-benchmark ( quot -- ) [ dup pprint benchmark ] collect-gc-events length " time: %d, gc events count: %d\n" printf ; inline
: foo ( arr -- arr ) [ 1 + ] map ;
: foo1 ( arr -- arr ) { } like [ 1 + ] map ;
TYPED: foo2 ( arr: array -- arr ) [ 1 + ] map ;
"===array===" print
gc dup [ foo ] my-benchmark drop
gc dup [ foo1 ] my-benchmark drop
gc dup [ foo2 ] my-benchmark drop
>string
: bar1 ( str -- str ) "" like [ 1 + ] map ;
TYPED: bar2 ( str: string -- str ) [ 1 + ] map ;
: baz ( str -- str ) "" like ;
: bar5 ( str -- str ) "" like baz [ 1 + ] map ;
: bar6 ( str -- str ) "" like baz "" like [ 1 + ] map ;

"===string===" print
gc dup [ foo ] my-benchmark drop
gc dup [ bar1 ] my-benchmark drop
gc dup [ bar2 ] my-benchmark drop
gc dup [ bar5 ] my-benchmark drop
gc dup [ bar6 ] my-benchmark drop
drop

outputs:

===array===
[ foo ] time: 62025530, gc events count: 0
[ foo1 ] time: 73359239, gc events count: 0
[ foo2 ] time: 26558404, gc events count: 0
===string===
[ foo ] time: 68609540, gc events count: 0
[ bar1 ] time: 8469329, gc events count: 0
[ bar2 ] time: 8494915, gc events count: 0
[ bar5 ] time: 75341227, gc events count: 0
[ bar6 ] time: 8494438, gc events count: 0
[ bar7 ] time: 136740495, gc events count: 0
[ bar8 ] time: 58144196, gc events count: 0

New Annotation

Summary:
Author:
Mode:
Body: