Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

rjbs
  (email not shown publicly)
http://rjbs.manxome.org/
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Thursday September 02, 2004
09:04 PM

perl is too slow

[ #20702 ]

...but first: an updated on my Apple Care.

I called back, ready to be bold and tell them, "A ha! It IS within warranty, because the product line is less than a year old!" I got cut off, "We don't offer phone support for that product, sir."

"I don't need phone support! I need an RMA number. It's mechanically broken."

"Use the web."

"You redid your support directory yesterday. There is no generic repair request page."

"Use an Apple Store."

"They're far away."

"Use your local repair place."

"It's not convenient! Just give me an RMA number. It will take less time than arguing!"

So, he puts me on hold for twenty minutes or so, and finally says, "Well, sir, I can get you a case number, but I'll have to charge you $50. When it's determined to be a hardware problem, though, we'll mark that non-billable and you won't get billed."

Right... well, buh-bye. The mouse goes to Double-Click this weekend, and I demand satisfaction.

Now, back to the topic at hand!

Someone on the LVLUG[1] mailing list asked for a simple way to randomly play a bunch of ogg files. His GUI players weren't working well. Another guy volunteered a shell script which was, imho, pretty primitive. I took the opportunity to show off Perl in its role as "better scripting" and produced this:

        http://rjbs.manxome.org/hacks/perl/#mprand

To defend his honor, the shell script author produced a program to randomize its arguments and reprint them to eliminate the need for a playlist file. It was written in C, 35 lines long, and... well, you know. It was C! I replied that this would do, in Perl: print sort{rand().5} [2]

Sure, it's lousy, but it works and took two seconds to think of and one more to write down.

"But Perl is too SLOW!" came the reply. A little benchmarking showed one iteration of Perl to be .004 seconds slower than C. Assuming it took ten minutes to code in C, it will only take 150,000 iterations for the author to regain his time. When will people learn? In almost all cases, to make shell scripts more cost-effective, reduce human time, not machine time.

[1] Lehigh Valley Linux Users Group

[2] Yes, that sorts input, not args. When I switched to @ARGV, I was surprised that it was faster to join with "\n" than to change the value of $, -- I am not interested enough to research, but maybe someone out there wants to tell me...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • In cases like that, before measuring the speed difference, ask him how fast it has to be. If it's fast enough, it's fast enough. It doesn't matter if Perl is twice, if the Perl code takes .5 seconds, and the C takes .25 and it needs to respond in 1.0.
    --

    --
    xoa

  • In a program to play 2 to 4 minute songs, its a wonder anyone's caring about a few milliseconds of program execution time between them.
    • It's a mind set fairly common among people who never looked beyond C/C++ in my experience.

      And even though they have a compiled language to play with, they still feel the need to micro-optimize as a matter of habit.