Speed Comparison Perl Python & C
From: Bart Nessux (bart_nessux_at_hotmail.com)
Date: 02/29/04
- Next message: PiedmontBiz: "Brent Ashley's JavaScript remote scripting (JSRS)"
- Previous message: Nemesis: "[ANN] XPN 0.2.2"
- Next in thread: Bob Ippolito: "Re: Speed Comparison Perl Python & C"
- Reply: Bob Ippolito: "Re: Speed Comparison Perl Python & C"
- Reply: Ville Vainio: "Re: Speed Comparison Perl Python & C"
- Reply: David Lees: "Re: Speed Comparison Perl Python & C"
- Reply: Nick Patavalis: "Re: Speed Comparison Perl Python & C"
- Reply: Jeremy Yallop: "Re: Speed Comparison Perl Python & C"
- Reply:(deleted message) Dennis Lee Bieber: "Re: Speed Comparison Perl Python & C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 29 Feb 2004 12:44:51 -0500
Just fooling around this weekend. Wrote and timed programs in C, Perl and
Python. Each Program counts to 1,000,000 and prints each number to the
console as it counts. I was a bit surprised. I'm not an expert C or Perl
programming expery, I'm most familiar with Python, but can use the others
as well.
Here are my results:
C = 23 seconds
Python = 26.5 seconds
Perl = 34.5 seconds
Here are the programs:
-------------------------
#The C version:
-------------------------
#include <stdio.h>
int main(void)
{
int x = 0;
while (x < 1000000) {
printf("%d \n", x++);
}
}
-------------------------
#The Python version:
-------------------------
#!/usr/bin/python
x = 0
while x < 1000000:
x = x + 1
print x
-------------------------
#The Perl version:
-------------------------
#!/usr/bin/perl -Tw
use strict;
my $x = 0;
while($x < 1000000) {
print $x++, "\n";
}
What do you guys think of this? I don't know enough about Perl & C, and
perhaps Python, to know if this was indeed a fair test. I thought C would
do this much faster than it did. Any ideas?
- Next message: PiedmontBiz: "Brent Ashley's JavaScript remote scripting (JSRS)"
- Previous message: Nemesis: "[ANN] XPN 0.2.2"
- Next in thread: Bob Ippolito: "Re: Speed Comparison Perl Python & C"
- Reply: Bob Ippolito: "Re: Speed Comparison Perl Python & C"
- Reply: Ville Vainio: "Re: Speed Comparison Perl Python & C"
- Reply: David Lees: "Re: Speed Comparison Perl Python & C"
- Reply: Nick Patavalis: "Re: Speed Comparison Perl Python & C"
- Reply: Jeremy Yallop: "Re: Speed Comparison Perl Python & C"
- Reply:(deleted message) Dennis Lee Bieber: "Re: Speed Comparison Perl Python & C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|