Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DataOutputStream performance under OS X



Don Werder <email@hidden> wrote:

>Are you saying that the other non-OS X operating systems are
>automatically buffering when reading and writing?

Probably. It depends on exactly how the JVM and its FileOutputStream class
is implemented.


> What is the cause
>in the improvement in the output times reported by Hagman on the
>Linux machines when comparing DataOutputStream and
>BufferedOutputStream? Is this additional buffering?

The cited tests are:
1. write 40,000 bytes to a BufferedOutputStream using write(int)
2. write 40,000 bytes to a DataOutputStream using writeByte(int)

Both streams are wrapped around a FileOutputStream. Both tests repeat 6
times, writing to a different file each time.

The baseline performance test, writing 40,000 bytes to
FileOutputStream.write(int), is not done. It is presumably about the same
as the DataOutputStream test. Even given how DataOutputStream is
implemented, it's still presumptive.

The default buffer-size for a BufferedOutputStream is 512 bytes, so every
512 bytes written by write(int) only calls
FileOutputStream.write(byte[],int,int) once to flush the buffer. It is
thus making 512 times fewer calls to the native FileOutputStream, and is
even calling a different method, whose implementation is platform-specific.
And a larger buffer-size may have even better performance.

So yes, the additional buffering is the principal cause of the speed
differences.


>Is DataOutputStream actually writing to disk and BufferOutputStream
>is writing to the buffer?

DataOutputStream is writing every byte to the FileOutputStream each time.
BufferedOutputStream is placing each byte in the buffer, and only writing
512-byte buffers to the FileOutputStream, and only when the buffer is full.
Neither one is actually writing to disk, per se, since both go through a
FileOutputStream.

On systems other than Mac OS X, FileOutputStream is apparently doing some
buffering of its own before writing to the disk Whether this is at the
FileOutputStream implementation level, or at the OS level, or has something
to do with the hardware, only a detailed examination of each JVM and
machine will tell. It may also be possible to glean information from other
tests, but without results one can only guess what the real reasons are.
Available evidence strongly suggests extra buffering.


> Is that what each time is measuring?

Probably.

It's not clear how the times were measured, since neither test contains
elapsed-time code, and both are simple main() classes. Thus, it's not
clear exactly what the times are measuring, since it's not clear whether
program startup time is included or not, nor the effects of process-image
caching, etc.

-- GG
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.