Re: [Newbies] Binary file I/O performance problems

2008-09-03 Thread Herbert König
Hello David,

DF focuses on just reading a small (for us) 123 Mb data file on disk. The
DF program takes about 166 seconds to run compared to 1.2 seconds for an
DF equivalent C version (140x faster than Squeak version).

number crunching and raw speed are not the points where Smalltalk
excels.

0 tinyBenchmarks gives '322824716 bytecodes/sec; 8945704 sends/sec'
which is about 9 million sends on my 1.8 GHz Pentium M.

In the browser when you will switch from Source to Byte codes in the
lowest pane (rightmost button) you will see the many sends in your
code. Some of these code fragments (e.g. the arithmetic) would be a
lot faster in any compiling language.

With this you can estimate the performance you can expect.

If it would only take one send per byte read from the file my Computer
would take about 10 seconds for 100MB.

That's the price for dynamically looking up the receiver's class for
every send.

So I guess this application is better left for other languages.


Cheers,


Herbertmailto:[EMAIL PROTECTED]

___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[Newbies] moving files on Windows

2008-09-03 Thread Waldemar Schwan

Hello everyone.

Normaly I'm developing on MacOS 10.5. As I tryed to run my code on a  
Windows Vista deleting a file throws me an


CannotDeleteFileException: Coud not delete the old version of file D: 
\waldemar\test\movingDestionation\moveMe.txt


Because the error don't tells me why the file can't be deletet I'm  
completly stumped. The file is writeable.


What I'm trying to do is to move a file from one folder to another. To  
acomplish that I create a readOnlyFileStream on the src-file an force  
the destinationdirectory to create a new file named like the src-file.  
After that I use FileDirectorycopyFile: to: .


moveLocalFile: aCBFile3DLocal toMountain: aCBMountain
| srcDir destDir srcFile destFile |
srcDir := aCBFile3DLocal file directory fileDirectory.
destDir := FileDirectory on: aCBMountain path.

srcFile := srcDir readOnlyFileNamed: aCBFile3DLocal file name.
srcFile binary.
destFile := destDir forceNewFileNamed: aCBFile3DLocal file name.
destFile binary.

srcDir copyFile: srcFile toFile: destFile.
srcDir deleteFileNamed:  aCBFile3DLocal file name.


Again: This code works on Mac but don't on Windows (Vista) allsow in  
compatibility mode.

I hope someone can give me a hint.



Best regards.
Waldemar
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[Newbies] Re: Binary file I/O performance problems

2008-09-03 Thread Klaus D. Witzel

Hi David,

let me respond in reverse order of your points:


I find it troubling that I am having to write code below the
abstraction level of C to read and write data from a file.  I thought
Smalltalk was supposed to free me from this kind of drudgery? Right
now, Java looks good and Python/Ruby look fantastic by comparison.


Here the difference to Squeak/Smalltalk is, that the intermediate level  
routines like #uint32 are made available at the Smalltalk language level  
where users can see them, use them and modify them. Such an approach is  
seen as part of an invaluable resource by Smalltalk users. It has a price,  
yes.


But Squeak/Smalltalk can do faster, dramatically faster than what you  
observed. The .image file (10s - 100s MB) is read from disk and  
de-endianessed in a second or so. Of course this is possible only because  
the file is in a ready-to-use format, but this can be a clue when you  
perhaps want to consider alternative input methods.



This (I think) cleans up some of the code smell, but for only marginal
performance improvements. It seems that I may need to implement a
buffer on the binary stream. Is there a good example on how this
should be done in the image or elsewhere?


I don't know of a particular example (specialized somehow on your problem  
at hand, for buffered reading of arbitrary structs) but this here is  
easy to do in Squeak:


  byteArray := ByteArray new: 2  20.
  actuallyTransferred :=
binaryStream readInto: byteArray startingAt: 1 count: byteArray size

You may perhaps want to check that GBs can be brought into Squeak's memory  
in a matter of seconds, just #printIt in a workspace:


[1024 timesRepeat: [[
(binaryStream := (SourceFiles at: 1) readOnlyCopy) binary.
byteArray := ByteArray new: 2  20.
  actuallyTransferred :=
binaryStream reset; readInto:
byteArray startingAt: 1 count: byteArray size]
 ensure: [binaryStream close]]] timeToRun

When reading from disk 4-byte-wise this makes a huge difference for sure.  
From here on you would use the ByteArray protocol (#byteAt:*, #shortAt:*,  
#longAt:*, #doubleAt:*) but as mentioned earlier these methods are perhaps  
not optimal (when compared to other languages and their implementation  
libraries) for you.


Last but not least, when doing performance critical i/o or conversions,  
Squeak users sometimes write a Squeak plugin (which then extends the  
Squeak VM), still at the Smalltalk/Slang language level but with it they  
can do/call any hw-oriented routine for speeding up things dramatically,  
and this indeed compares well to other languages and their implementation  
libraries :)


HTH.

/Klaus


On Wed, 03 Sep 2008 08:00:54 +0200, David Finlayson wrote:

OK - I made some of the suggested changes. I broke the readers into two  
parts:


uint32
returns the next unsigned, 32-bit integer from the binary
stream
isBigEndian
ifTrue: [^ self nextBigEndianNumber: 4]
ifFalse: [^ self nextLittleEndianNumber: 4]

Where nextLittleEndianNumber looks like this:

nextLittleEndianNumber: n
Answer the next n bytes as a positive Integer or
LargePositiveInteger, where the bytes are ordered from least
significant to most significant.
Copied from PositionableStream
| bytes s |
[bytes := stream next: n.
s := 0.
n
to: 1
by: -1
do: [:i | s := (s bitShift: 8)
bitOr: (bytes at: i)].
^ s]
on: Error
do: [^ nil]



David



___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[Newbies] how do I get rid of things that pointer finder points to?

2008-09-03 Thread Freeman Mayberry
I figured out how to find bad reference to obsolete objects using pointer
finder, but I still don't really understand how to hunt it down and get rid
of it.

-- 
Freeman Mayberry
___
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners