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



Jussi Hagman <email@hidden> wrote:

>Maybe so, but when writing at 12kB/s the program is also using every
>CPU-cycle available so perhaps it would be a bit faster with a faster
>CPU...

A faster CPU will not make nearly as much difference as using the Java I/O
classes well.

That usually means placing a BufferedOutputStream between a
FileOutputStream and anything else writing to it. That may mean tuning
buffer-sizes, too. I usually start with 4K, but you may be happy with the
1/2-K default.


>However, if I understood correctly this is as it it is supposed
>to be.

It's not "supposed to be" any particular way. It's just that it can vary
across platforms, depending on implementation. Apple implemented it one
way. Sun implemented it another way. Both are correct, and both are
"supposed to be" exactly what they are: different implementations.


>Thankfully I do not have the need to use Java at the moment. If
>the need arises it seems that I'd probably be better off with another
>operating system.

You'd be much better off learning to use the Java I/O classes well.

When I ran your tests on my machine, I measured a 150X difference in speed
between the buffered BOSTest (82 ms) and the unbuffered DOSTest (11952 ms),
after I added code to measure elapsed time. To satisfy my curiousity, I
wrote a FOSTest that calls FileOutputStream.write(int), too. As expected,
it is essentially the same speed as DOSTest, since neither one performs any
additional buffering.

I suspect most of the BOSTest's elapsed time is spent creating the files,
not writing to them. 6 files in 82 ms is only about 13 ms each, and
file-creation is always unbuffered, so you have no control over that. But
you have quite a lot of control over how you use the I/O classes.

-- 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.