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 ( -- stream ) "/dev/random" binary ; : to-target ( -- stream ) "/tmp/floats.bin" binary ; : make-float ( n -- f ) le> bits>float ; : clip ( n -- n ) 1000.0 min -1000.0 max ; : sum-floats ( -- o ) "/tmp/floats.bin" 4000000 [ 4 0 [ make-float clip + 2 / ] reduce ] with-mapped-file ; : sum-floats1 ( -- o ) "/tmp/floats.bin" 4000000 [ 0 swap dup length 4 / swap address>> [ float-nth clip + 2 / ] curry each ] with-mapped-file ; : r ( -- stream ) from-source [ 4000000 read ] with-input-stream ; : w ( stream -- ) to-target [ write ] with-output-stream ; : init ( -- ) r w ; : test1 ( -- ) [ sum-floats ] time ; : test2 ( -- ) [ sum-floats1 ] time ; MAIN: init