Dear Matt,

On Dec 2, 5:29 pm, matthew.leonha...@gmail.com (Matt) wrote:
> > Maybe it's not so suitable to ask this here.
> > But is there a good way (code sample?) to implement a speed test
> > between Perl and C?
> > For a project which handles lots of data we want to know how slower
> > perl is than C.
>
> > Thanks.
>
> To perform the test, I'd just use 'time':
>
> test.cc:
> int main()
> {
>         int a = 1 + 1;
>
> }
>
> test.pl:
> #!/sw/bin/perl
> $a = 1 + 1;
>
> # time bash -c 'for x in {1..100}; do ./a.out; done'
>
> real    0m0.167s
> user    0m0.029s
> sys     0m0.138s
>
> # time bash -c 'for x in {1..100}; do ./test2.pl; done'
>
> real    0m0.435s
> user    0m0.154s
> sys     0m0.247s
>
> So...I've proved that in my specific environment, C is (~3x) faster
> than Perl at adding 1+1...Now as far as what tests you want to
> implement, that's up to you and your specific needs.

In fact no :-) This does not prove anything. The program is so short
that the time to load and link it (C) or to start the perl interpret
and interpret it is more significant than the time to do (1+1).

The 'noise' of the measurement and the startup time completely hide
the real computation time.
For this reason you should repeat the 'action' you want to test inside
the benchmark not outside.

Another important point is that your program does nothing (the
variable a is never used) and a decent compiler would optimize it and
remove the statement. You are in fact benchmarking an 'empty'
application.

Matteo


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