From: Jordan Callicoat Date: 2006-08-29T17:21:24+09:00 Subject: Re: For performance, write it in C =?iso-8859-1?Q?J=FCrgen?= Strobel wrote: > On Sat, Aug 26, 2006 at 11:23:02PM +0900, Jordan Callicoat wrote: >> J端rgen Strobel wrote: > >> Yes! That's exactly what I was trying to do! I was trying to show that >> writing to stdout (assuming a comparable context, like an xterm) is the >> bottle-neck of the ruby version here. Writing to a file was about 90 >> times faster. Like I said, I wasn't denying that C is faster; my point >> was this: the C version may only take 5 seconds to write to a *file*, >> but ruby only takes 17 seconds; and for me, as I'm sure for others, 12 >> seconds is not worth the effort of writing it in C. So the 12 minutes to >> 5 seconds comparison was flawed -- 17 seconds to 5 seconds is more >> accurate. > > Usually you don't benchmark with external arbitrary bottlenecks > enabled. The point is, *your* xterm may be of very different speed > than mine. Generic terminal emulators are not a comparable context at > all, not without benchmarking them themselves, which is not the point > of this exercise. > > I should have emphasized *your terminal emulator*. We are comparing > ruby vs. C, so it makes sense to assume a fast and uniform output > mechanism which doesn't get in our way. It is standard practice to > write to stdout, but redirect it to /dev/null or files if writeing > larger quantities in benchmarks. > > To get real numbers, your C version took 0.010s CPU time, and your > ruby one took 0.202s. A difference of roughly 2000% may well be > important to several applications. Sometimes it may be completely > irrelevant, for instance if CPU time is dwarfed by I/O. > > -J端rgen I understand your point, but I think we may be talking past each other here. My purpose was to show that the ruby (and assumedly perl) bottle-neck was due other factors than the interpreter. Granted, ruby is slower than C -- even a lot slower (2000%!) -- but the end result of writing to a *file* is 17 seconds in ruby. That is light years removed from 26 (or even 12) minutes (i.e., writing to stdout with no redirection). So while 12 minutes versus 5 seconds may make you want to write it in C; 17 seconds versus 5 seconds may make you think twice about it. My question is, when is C a *necessary* evil, rather than just an evil. ;) Regards, Jordan -- Posted via http://www.ruby-forum.com/.