Before (using strings): 77MiB/s
After (using byte-arrays): 3.06GiB/s
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: command-line formatting kernel io io.encodings.binary
-io.files namespaces sequences strings ;
+USING: accessors command-line formatting fry io io.encodings
+io.encodings.binary io.files kernel namespaces sequences ;
-: cat-lines ( -- )
- [ print flush ] each-line ;
-
- [ >string write flush ] each-block ;
+ input-stream get dup decoder? [ stream>> ] when
+ output-stream get dup encoder? [ stream>> ] when
+ '[ _ stream-write ] each-stream-block ;
: cat-file ( path -- )
dup exists? [
: cat-file ( path -- )
dup exists? [
] [ "%s: not found\n" printf flush ] if ;
: cat-files ( paths -- )
] [ "%s: not found\n" printf flush ] if ;
: cat-files ( paths -- )
- [ dup "-" = [ drop cat-lines ] [ cat-file ] if ] each ;
+ [ dup "-" = [ drop cat-stream ] [ cat-file ] if ] each ;
- command-line get [ cat-lines ] [ cat-files ] if-empty ;
+ command-line get [ cat-stream ] [ cat-files ] if-empty ;