Paste: http://www.wagerlabs.com/blog/2008/01/introducing-fac.html
Author: | cadar777 |
Mode: | factor |
Date: | Sun, 9 Nov 2008 15:08:02 |
Plain Text |
USING: kernel io.encodings.binary io.files io.binary math math.order grouping sequences io.mmap accessors alien.c-types io tools.time ;
IN: my
: from-source "/dev/random" binary <file-reader> ;
: to-target "/tmp/floats.bin" binary <file-writer> ;
: make-float le> bits>float ;
: clip 1000.0 min -1000.0 max ;
: sum-floats
"/tmp/floats.bin" 4000000 [
4 <sliced-groups> 0 [ make-float clip + 2 / ] reduce
] with-mapped-file ;
: sum-floats1
"/tmp/floats.bin" 4000000 [
0 swap dup length 4 / swap address>>
[ float-nth clip + 2 / ] curry each
] with-mapped-file ;
: r from-source [ 4000000 read ] with-input-stream ;
: w to-target [ write ] with-output-stream ;
: init r w ;
: test1 [ sum-floats ] time ;
: test2 [ sum-floats1 ] time ;
MAIN: init
New Annotation