Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: msoap/factorial-multi-language
base: b3960b1556
...
head fork: msoap/factorial-multi-language
compare: b6b22a8d22
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 119 additions and 35 deletions.
  1. +2 −0  .gitignore
  2. +39 −20 README.md
  3. +43 −15 create-report.pl
  4. +14 −0 fact-perl6.pl
  5. +21 −0 fact.awk
View
2  .gitignore
@@ -1,2 +1,4 @@
report.dat
fact_c
+chart*.png
+report.md
View
59 README.md
@@ -1,8 +1,8 @@
-Подсчет факториала на разных языках
-===================================
+Comparison of languages for speed by calculation of factorial in different languages
+====================================================================================
-Аппаратные средства:
---------------------
+Hardware:
+---------
Название модели: MacBook Pro
Идентификатор модели: MacBookPro7,1
@@ -20,6 +20,12 @@ Perl (5.12.3)
perl finish 1000000 - ok
./fact.pl 7.91s user 0.01s system 99% cpu 7.919 total
+Perl6 (2011.04 built on parrot 3.6.0)
+-------------------------------------
+
+ perl6 finish 1000 - ok
+ ./fact-perl6.pl 8.32s user 0.20s system 97% cpu 8.746 total
+
Python (2.7.1)
--------------
@@ -68,22 +74,35 @@ PHP (5.3.8)
php finish 1000000 - ok
./fact.php 5.64s user 0.02s system 99% cpu 5.673 total
+AWK (20070501)
+--------------
+
+ awk finish 1000000 - ok
+ ./fact.awk 5.79s user 0.00s system 99% cpu 5.806 total
+
Report:
-------
-### text chart:
- luajit - 9972006 rps (x133) **********************************************************************
- C - 6812701 rps (x91 ) ***********************************************
- JavascriptCore - 4847180 rps (x65 ) **********************************
- node.js - 4439017 rps (x59 ) *******************************
- lua - 454555 rps (x6 ) ***
- python - 195261 rps (x2 ) *
- php - 185238 rps (x2 ) *
- perl - 115323 rps (x1 )
- ruby - 74500 rps (x1 )
-
-###all languages:
-![Chart for all languages](https://chart.googleapis.com/chart?cht=bhs&chs=800x200&chd=t%3A9972006%2C6812701%2C4847180%2C4439017%2C454555%2C195261%2C185238%2C115323%2C74500&chco=4d89f9&chbh=15&chds=0,9972006.58311987&chxt=x,y,r&chxl=1%3A%7Cruby%7Cperl%7Cphp%7Cpython%7Clua%7Cnode.js%7CJavascriptCore%7CC%7Cluajit%7C2%3A%7C74500%20rps%7C115323%20rps%7C185238%20rps%7C195261%20rps%7C454555%20rps%7C4439017%20rps%7C4847180%20rps%7C6812701%20rps%7C9972006%20rps%7C0%3A%7C0%20%25%7C10%20%25%7C20%20%25%7C30%20%25%7C40%20%25%7C50%20%25%7C60%20%25%7C70%20%25%7C80%20%25%7C90%20%25%7C100%20%25)
-
-###languages without JIT/compile:
-![Chart for slow languages](https://chart.googleapis.com/chart?cht=bhs&chs=800x130&chd=t%3A454555%2C195261%2C185238%2C115323%2C74500&chco=4d89f9&chbh=15&chds=0,454555.854232423&chxt=x,y,r&chxl=1%3A%7Cruby%7Cperl%7Cphp%7Cpython%7Clua%7C2%3A%7C74500%20rps%7C115323%20rps%7C185238%20rps%7C195261%20rps%7C454555%20rps%7C0%3A%7C0%20%25%7C10%20%25%7C20%20%25%7C30%20%25%7C40%20%25%7C50%20%25%7C60%20%25%7C70%20%25%7C80%20%25%7C90%20%25%7C100%20%25)
+###report all (Sun Mar 18 20:38:20 2012):
+
+ luajit - 9613216 rps: **********************************************************************
+ C - 6848418 rps: *************************************************
+ JavascriptCore - 4750887 rps: **********************************
+ node.js - 4486641 rps: ********************************
+ lua - 448643 rps: ***
+ python - 183658 rps: *
+ awk - 178267 rps: *
+ php - 171625 rps: *
+ perl - 113564 rps:
+ ruby - 73900 rps:
+ perl6 - 118 rps:
+
+![Chart for all all](https://chart.googleapis.com/chart?cht=bhs&chs=700x245&chd=t%3A9613216%2C6848418%2C4750887%2C4486641%2C448643%2C183658%2C178267%2C171625%2C113564%2C73900%2C118&chco=4d89f9&chbh=15&chds=0,9613216.09567688&chxt=x,y,r&chxl=1%3A%7Cperl6%7Cruby%7Cperl%7Cphp%7Cawk%7Cpython%7Clua%7Cnode.js%7CJavascriptCore%7CC%7Cluajit%7C2%3A%7C118%20rps%7C73900%20rps%7C113564%20rps%7C171625%20rps%7C178267%20rps%7C183658%20rps%7C448643%20rps%7C4486641%20rps%7C4750887%20rps%7C6848418%20rps%7C9613216%20rps%7C0%3A%7C0%20%25%7C10%20%25%7C20%20%25%7C30%20%25%7C40%20%25%7C50%20%25%7C60%20%25%7C70%20%25%7C80%20%25%7C90%20%25%7C100%20%25)
+
+###report fast (Sun Mar 18 20:38:30 2012):
+
+![Chart for all fast](https://chart.googleapis.com/chart?cht=bhs&chs=700x105&chd=t%3A9613216%2C6848418%2C4750887%2C4486641&chco=4d89f9&chbh=15&chds=0,9613216.09567688&chxt=x,y,r&chxl=1%3A%7Cnode.js%7CJavascriptCore%7CC%7Cluajit%7C2%3A%7C4486641%20rps%7C4750887%20rps%7C6848418%20rps%7C9613216%20rps%7C0%3A%7C0%20%25%7C10%20%25%7C20%20%25%7C30%20%25%7C40%20%25%7C50%20%25%7C60%20%25%7C70%20%25%7C80%20%25%7C90%20%25%7C100%20%25)
+
+###report other (Sun Mar 18 20:38:40 2012):
+
+![Chart for all other](https://chart.googleapis.com/chart?cht=bhs&chs=700x165&chd=t%3A448643%2C183658%2C178267%2C171625%2C113564%2C73900%2C118&chco=4d89f9&chbh=15&chds=0,448643.615756483&chxt=x,y,r&chxl=1%3A%7Cperl6%7Cruby%7Cperl%7Cphp%7Cawk%7Cpython%7Clua%7C2%3A%7C118%20rps%7C73900%20rps%7C113564%20rps%7C171625%20rps%7C178267%20rps%7C183658%20rps%7C448643%20rps%7C0%3A%7C0%20%25%7C10%20%25%7C20%20%25%7C30%20%25%7C40%20%25%7C50%20%25%7C60%20%25%7C70%20%25%7C80%20%25%7C90%20%25%7C100%20%25)
View
58 create-report.pl
@@ -22,6 +22,8 @@
}
);
+our %is_fast = map {$_ => 1} qw/luajit C JavascriptCore node.js/;
+
# ------------------------------------------------------------------------------
sub calc {
my %result;
@@ -61,7 +63,7 @@ sub calc {
# ------------------------------------------------------------------------------
sub create_report {
- print "Report:\n";
+ my ($name, $grep_sub) = @_;
my $VAR1;
open my $FH, '<', $report_data or die "Error open file: $!\n";
@@ -69,35 +71,61 @@ sub create_report {
die "$report_data is not valid" if $@;
close $FH;
- # without fasters languages
- # delete $VAR1->{$_} for qw/luajit C JavascriptCore node.js/;
+ # grep by speed
+ my $stat = {map {$_ => $VAR1->{$_}}
+ grep {$grep_sub->($_)}
+ keys %$VAR1
+ };
+
+ my $max_rps = max(values %$stat);
+ my $min_rps = min(values %$stat);
+ my $result_report_md = '';
- my $max_rps = max(values %$VAR1);
- my $min_rps = min(values %$VAR1);
- for my $lang (sort {$VAR1->{$b} <=> $VAR1->{$a}} keys %$VAR1) {
- my $rps = $VAR1->{$lang};
+ print "Report $name:\n";
+ $result_report_md .= sprintf "###report $name (%s):\n\n", localtime() . "";
+ for my $lang (sort {$stat->{$b} <=> $stat->{$a}} keys %$stat) {
+ my $rps = $stat->{$lang};
my $gistogr_line = '*' x (70 * $rps / $max_rps);
- printf "%15s - %7i rps (x%-3i) %s\n", $lang, $rps, $rps / $min_rps, $gistogr_line;
+ printf "%15s - %7i rps: %s\n", $lang, $rps, $gistogr_line;
+ $result_report_md .= sprintf " %15s - %7i rps: %s\n", $lang, $rps, $gistogr_line;
}
+ $result_report_md .= "\n";
+ printf "\n";
# google image chart
- my $chd = "t:" . join ",", map {int($VAR1->{$_})} sort {$VAR1->{$b} <=> $VAR1->{$a}} keys %$VAR1;
+ my $chd = "t:" . join ",", map {int($stat->{$_})} sort {$stat->{$b} <=> $stat->{$a}} keys %$stat;
$chd = uri_escape($chd);
- my $chxl = "1:|" . join "|", sort {$VAR1->{$a} <=> $VAR1->{$b}} keys %$VAR1;
- $chxl .= "|2:|" . join "|", map {int($VAR1->{$_}) . ' rps'} sort {$VAR1->{$a} <=> $VAR1->{$b}} keys %$VAR1;
+ my $chxl = "1:|" . join "|", sort {$stat->{$a} <=> $stat->{$b}} keys %$stat;
+ $chxl .= "|2:|" . join "|", map {int($stat->{$_}) . ' rps'} sort {$stat->{$a} <=> $stat->{$b}} keys %$stat;
$chxl .= "|0:|" . join "|", map {$_ * 10 . " %"} 0 .. 10;
$chxl = uri_escape($chxl);
-
- my $url = "https://chart.googleapis.com/chart?cht=bhs&chs=1000x200&chd=$chd&chco=4d89f9&chbh=15&chds=0,$max_rps&chxt=x,y,r&chxl=$chxl";
- print "\n$url\n";
+ my $height_one = 15;
+ my $height = scalar(1 + keys %$stat) * ($height_one + 5) + 5;
+ my $width = 700;
+
+ my $url = "https://chart.googleapis.com/chart?cht=bhs&chs=${width}x$height&chd=$chd&chco=4d89f9&chbh=$height_one&chds=0,$max_rps&chxt=x,y,r&chxl=$chxl";
+ $result_report_md .= "![Chart for all $name]($url)\n\n";
system("open", $url) if $^O eq 'darwin';
+ system("curl -s '$url' > chart_$name.png");
+
+ return $result_report_md;
}
# ------------------------------------------------------------------------------
sub main {
die "$0 [ --help | --calc | --create ]\n" if $ARGV[0] && $ARGV[0] eq '--help';
calc() if ! @ARGV || $ARGV[0] eq '--calc';
- create_report() if ! @ARGV || $ARGV[0] eq '--create';
+
+ if (! @ARGV || $ARGV[0] eq '--create') {
+ my $result_report_md = '';
+ $result_report_md .= create_report('all', sub () {1});
+ $result_report_md .= create_report('fast', sub () {$is_fast{$_[0]} ? 1 : 0});
+ $result_report_md .= create_report('other', sub () {$is_fast{$_[0]} ? 0 : 1});
+
+ open my $FHR, '>', 'report.md' or die "Error open file: $!\n";
+ print $FHR $result_report_md;
+ close $FHR;
+ }
}
# ------------------------------------------------------------------------------
View
14 fact-perl6.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl6
+
+my Int $times = 1_000;
+my Int $fact_16 = 20922789888000;
+
+# ------------------------------------------------------------------------------
+sub fact(Int $n) {
+ return 1 if $n == 1;
+ return $n * fact($n - 1);
+}
+
+my Bool $ok = True;
+$ok &&= fact(16) == $fact_16 for 1 .. $times;
+say("perl6 finish $times - " ~ ($ok ?? 'ok' !! 'fail'));
View
21 fact.awk
@@ -0,0 +1,21 @@
+#!/usr/bin/env awk -f
+
+function fact(n) {
+ if (n == 1)
+ return 1
+ return (n * fact(n - 1))
+}
+
+BEGIN {
+ times = 1000000
+ fact_16 = 20922789888000
+
+ ok = 1
+ for (i = 0; i < times; i++) {
+ # res = fact(16)
+ ok = ok && fact(16) == fact_16
+ }
+
+ print "awk finish " times " - " (ok ? "ok" : "fail")
+ exit
+}

No commit comments for this range

Something went wrong with that request. Please try again.