Skip to content

Instantly share code, notes, and snippets.

@alexandregz
Last active October 1, 2015 15:39
Show Gist options
  • Save alexandregz/bf595716afac0f293ec4 to your computer and use it in GitHub Desktop.
Save alexandregz/bf595716afac0f293ec4 to your computer and use it in GitHub Desktop.
Test perl/perl6/php/php7/C
#include <stdio.h>
#include <math.h>
int main() {
double s=0;
for(int i=1; i<=10000; i++) {
s=s+(1/pow(i, 2));
printf("%d %lf %lf %lf\n", i, s, pow(i,2), 1/pow(i,2) );
}
printf("done: %lf\n", s);
return 0;
}
#include <stdio.h>
#include <math.h>
int main() {
double s=0;
for(int i=1; i<=10000; i++) {
s=s+(1/pow(i, 2));
// printf("%d %lf %lf %lf\n", i, s, pow(i,2), 1/pow(i,2) );
}
printf("done: %lf\n", s);
return 0;
}
#!/bin/sh
echo "perl6 optimized with output\n"
time perl6 -e 'my Num $s; for 1..10000 {$s+=1e0/$_**2;say $s~"--"~$_~"--"~(1e0/$_**2)~"--"~($_**2);};say "done $s"'
echo "perl6 optimized without output\n"
time perl6 -e 'my Num $s; for 1..10000 {$s+=1e0/$_**2;};say "done: $s"'
#!/bin/sh
echo "perl6 with output\n"
time perl6 -e 'my $s; for 1..10000 {$s+=1/$_**2;say $s~"--"~$_~"--"~(1/$_**2)~"--"~($_**2);};say "done $s"'
echo "perl6 without output\n"
time perl6 -e 'my $s; for 1..10000 {$s+=1/$_**2;};say "done: $s"'
#!/bin/sh
echo "perl with output\n"
time perl -e 'my $s; for(1..10000) {$s+=1/$_**2; print "$s--$_--".(1/$_**2)."--".($_**2)."\n";};print "done: $s"'
echo "perl without output\n"
time perl -e 'my $s; for(1..10000) {$s+=1/$_**2;};print "done: $s"'
#!/bin/sh
echo "test with output"
time /usr/local/opt/phpng/bin/php -r '$a=0;for($i=1; $i <= 10000; $i++){$a+=1/$i**2;print "$i--$a--".(1/$i**2)."--".($i**2)."\n";};print "done $a";'
echo "test without output"
time /usr/local/opt/phpng/bin/php -r '$a=0;for($i=1; $i <= 10000; $i++){$a+=1/$i**2;};print "done $a";'
#!/bin/sh
echo "test with output"
time php -r '$a=0;for($i=1; $i <= 10000; $i++){$a+=1/$i**2;print "$i--$a--".(1/$i**2)."--".($i**2)."\n";};print "done $a";'
echo "test without output"
time php -r '$a=0;for($i=1; $i <= 10000; $i++){$a+=1/$i**2;};print "done $a";'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment