>>>>> "m" == matt  <matthew.leonha...@gmail.com> writes:

  m> To perform the test, I'd just use 'time':

that is a very poor way to compare speed. it doesn't account for perl's
startup time vs running time.

  m> test.cc:
  m> int main()
  m> {
  m>         int a = 1 + 1;
  m> }

  m> test.pl:
  m> #!/sw/bin/perl
  m> $a = 1 + 1;

  m> # time bash -c 'for x in {1..100}; do ./a.out; done'

you also don't account for the overhead in the shell code which can be
very large.

also your test code in both cases doesn't even test what you claim it
does. both perl and c will fold that constant expression 1 + 1 into 2 at
compile time. but you only compile c once and you compile the perl each
time in the iterations. so you are really comparing assigning 2 to a
variable. and it is well know that basic c will be much faster than
basic perl.

  m> real    0m0.167s
  m> user    0m0.029s
  m> sys     0m0.138s

  m> # time bash -c 'for x in {1..100}; do ./test2.pl; done'

  m> real    0m0.435s
  m> user    0m0.154s
  m> sys     0m0.247s

  m> So...I've proved that in my specific environment, C is (~3x) faster
  m> than Perl at adding 1+1...Now as far as what tests you want to
  m> implement, that's up to you and your specific needs.

sorry, you haven't proved anything.

try this with some string or regex oriented code. the time
it takes you to code it up in c will dwarf the differences in run
times. and programmer time these days is much more expensive than cpu
time.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to