in reply to Re^2: Why is this code so much slower than the same algorithm in C?
in thread Why is this code so much slower than the same algorithm in C?
You don't have throw the baby out with the bath water in order to benefit from good performance:
#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => '_729090', CLEAN_AFTER_BUILD => 0; #include <stdlib.h> #include <string.h> #include <stdio.h> SV* thing() { int i, j; for (i = 20; ; i += 20) { for (j = 1; j < 20; j++) { if (i % j) break; } if (j == 20) { return newSViv( i ); break; } } } END_C print time; print thing(); print time; __END__ C:\test>729090-IC.pl 1228813945 232792560 1228813946
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Why is this code so much slower than the same algorithm in C?
by pobocks (Chaplain) on Dec 09, 2008 at 13:38 UTC | |
by BrowserUk (Patriarch) on Dec 09, 2008 at 14:06 UTC |