3 Sep 00:36
Binary file I/O performance problems
From: David Finlayson <dfinlayson <at> usgs.gov>
Subject: Binary file I/O performance problems
Newsgroups: gmane.comp.lang.smalltalk.squeak.beginners
Date: 2008-09-02 22:38:36 GMT
Subject: Binary file I/O performance problems
Newsgroups: gmane.comp.lang.smalltalk.squeak.beginners
Date: 2008-09-02 22:38:36 GMT
I've been working on my first Smalltalk program which needs to read and write large c structs from a binary file. I wrote two classes BinaryStreamReader and BinaryStreamWriter that take a stream and can read (or write) all of the integer and floating point types I need (also handles byte-swapping if necessary). I wrote a test program that focuses on just reading a small (for us) 123 Mb data file on disk. The program takes about 166 seconds to run compared to 1.2 seconds for an equivalent C version (140x faster than Squeak version). As an example of the style of code I've written, here is the method that reads an unsigned 32-bit integer: uint32 " returns the next unsigned, 32-bit integer from the binary stream " " see PositionableStream for original implimentation." | n a b c d | isBigEndian ifTrue: [ a := stream next. b := stream next. c := stream next. d := stream next ] ifFalse: [ d := stream next. c := stream next. b := stream next. a := stream next ]. ((((a notNil and: [ b notNil ]) and: [ c notNil ])) and: [ d notNil]) ifTrue: [ n := a.(Continue reading)
RSS Feed