Skip to content

Commit f337acf

Browse files
author
H.Merijn Brand - Tux
committedDec 31, 2015
Also test python speeds
Gosh, I hate that illogical language
1 parent e334081 commit f337acf

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed
 

‎csv-python2.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
import csv
3+
4+
n = 0
5+
csvreader = csv.reader (sys.stdin, delimiter=",", quotechar='"')
6+
for row in csvreader:
7+
n += len (row)
8+
9+
print n

‎csv-python3.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
import csv
3+
4+
n = 0
5+
csvreader = csv.reader (sys.stdin, delimiter=",", quotechar='"')
6+
for row in csvreader:
7+
n += len (row)
8+
9+
print (n)

‎time.pl

+25-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
[ 6, "test" ],
2929
[ 6, "test-t" ],
3030
[ 6, "csv-parser" ],
31+
[ 2, "csv-python2" ],
32+
[ 3, "csv-python3" ],
3133
);
3234
my %perl = (
35+
2 => "python2",
36+
3 => "python3",
3337
5 => "perl",
3438
6 => "perl6",
3539
);
@@ -53,18 +57,30 @@
5357

5458
printf "%-11s ", $_->[1];
5559

56-
open my $ph, "|-", "$perl{$v} -Ilib $script.pl 2>&1 >/dev/null";
57-
print $ph "\n";
58-
close $ph;
60+
my ($i, $t0) = (0);
61+
if ($v >= 5) {
62+
open my $ph, "|-", "$perl{$v} -Ilib $script.pl 2>&1 >/dev/null";
63+
print $ph "\n";
64+
close $ph;
5965

60-
my $t0 = [ gettimeofday ];
61-
open my $th, "-|", "$perl{$v} -Ilib $script.pl 2>&1 </tmp/hello.csv";
62-
my $i = 0;
63-
while (<$th>) {
64-
m/^(\d+)$/ and $i = $1;
66+
$t0 = [ gettimeofday ];
67+
open my $th, "-|", "$perl{$v} -Ilib $script.pl 2>&1 </tmp/hello.csv";
68+
while (<$th>) {
69+
m/^(\d+)$/ and $i = $1;
70+
}
71+
}
72+
else {
73+
open my $ph, "|-", "$perl{$v} $script.py 2>&1 >/dev/null";
74+
print $ph "\n";
75+
close $ph;
76+
77+
$t0 = [ gettimeofday ];
78+
open my $th, "-|", "$perl{$v} $script.py 2>&1 </tmp/hello.csv";
79+
while (<$th>) {
80+
m/^(\d+)$/ and $i = $1;
81+
}
6582
}
6683
my $elapsed = tv_interval ($t0);
67-
close $th;
6884
printf "%s %6d %9.3f %9.3f\n", $i eq 50000 ? " " : "***", $i,
6985
$elapsed, $elapsed - $start{$v};
7086
}

0 commit comments

Comments
 (0)