Speed Comparison Perl Python & C

Bart Nessux bart_nessux at hotmail.com
Sun Feb 29 18:44:51 CET 2004

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:


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? 

More information about the Python-list mailing list