should more closely match your original C code.#!/usr/bin/perl sub test { my ( $i, $j ); for ( $i = 20; ; $i += 20 ) { for ( $j = 1; $j < 20; $j++ ) { last if ( $i % $j ); } if ( $j == 20 ) { printf( "Number: %d\n", $i ); last; } } return( 0 ); } test();
But even after re-writing to match your original algorithm this takes 20 odd seconds on my machine. When I add use integer; it cuts it down to 13 seconds.
In reply to Re: Why is this code so much slower than the same algorithm in C?
by monarch
in thread Why is this code so much slower than the same algorithm in C?
by wanna_code_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |