Last active
September 11, 2016 19:28
-
-
Save owulveryck/4f9ddb952c5f1ef708b60a9907733969 to your computer and use it in GitHub Desktop.
CSV parsing comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in $(seq 1 600000) | |
do | |
echo SERVER$((RANDOM%800+100)),$RANDOM,$RANDOM,$RANDOM >> sample.csv | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/csv" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"strconv" | |
) | |
func main() { | |
var output = make(map[string]int, 0) | |
in, err := os.Open("sample.csv") | |
if err != nil { | |
log.Fatal(err) | |
} | |
r := csv.NewReader(in) | |
r.LazyQuotes = true | |
for { | |
record, err := r.Read() | |
if err == io.EOF { | |
break | |
} | |
if err != nil { | |
log.Fatal(err) | |
} | |
s, err := strconv.Atoi(record[1]) | |
if err != nil { | |
log.Println(err) | |
} | |
output[record[0]] = output[record[0]] + s | |
} | |
fmt.Println(output["SERVER788"]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my $file = 'sample.csv'; | |
my %data; | |
open(my $fh, '<', $file) or die "Can't read file '$file' [$!]\n"; | |
while (my $line = <$fh>) { | |
chomp $line; | |
my @fields = split(/,/, $line); | |
$data{$fields[0]} = $data{$fields[0]} + $fields[1] | |
#push @data, \@fields; | |
} | |
print "$data{'SERVER788'}\n" | |
#use Data::Dumper; | |
#print Dumper(%data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import csv | |
fname = "sample.csv" | |
file = open(fname, "rb") | |
reader = csv.reader(file) | |
result = {} | |
for row in reader: | |
try: | |
result[row[0]] = result[row[0]] + int(row[1]) | |
except: | |
result[row[0]] = int(row[1]) | |
print result['SERVER788'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# go | |
$ /usr/bin/time -v ./main | |
12220632 | |
Command being timed: "./main" | |
User time (seconds): 1.65 | |
System time (seconds): 0.02 | |
Percent of CPU this job got: 98% | |
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.71 | |
Average shared text size (kbytes): 0 | |
Average unshared data size (kbytes): 0 | |
Average stack size (kbytes): 0 | |
Average total size (kbytes): 0 | |
Maximum resident set size (kbytes): 6156 | |
Average resident set size (kbytes): 0 | |
Major (requiring I/O) page faults: 0 | |
Minor (reclaiming a frame) page faults: 1641 | |
Voluntary context switches: 285 | |
Involuntary context switches: 325 | |
Swaps: 0 | |
File system inputs: 0 | |
File system outputs: 0 | |
Socket messages sent: 0 | |
Socket messages received: 0 | |
Signals delivered: 0 | |
Page size (bytes): 4096 | |
Exit status: 0 | |
# python | |
$ /usr/bin/time -v ./main.py | |
12220632 | |
Command being timed: "./main.py" | |
User time (seconds): 2.20 | |
System time (seconds): 0.02 | |
Percent of CPU this job got: 97% | |
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.28 | |
Average shared text size (kbytes): 0 | |
Average unshared data size (kbytes): 0 | |
Average stack size (kbytes): 0 | |
Average total size (kbytes): 0 | |
Maximum resident set size (kbytes): 5180 | |
Average resident set size (kbytes): 0 | |
Major (requiring I/O) page faults: 0 | |
Minor (reclaiming a frame) page faults: 1429 | |
Voluntary context switches: 1 | |
Involuntary context switches: 552 | |
Swaps: 0 | |
File system inputs: 0 | |
File system outputs: 0 | |
Socket messages sent: 0 | |
Socket messages received: 0 | |
Signals delivered: 0 | |
Page size (bytes): 4096 | |
Exit status: 0 | |
# perl | |
$ /usr/bin/time -v ./main.pl | |
12220632 | |
Command being timed: "./main.pl" | |
User time (seconds): 3.19 | |
System time (seconds): 0.01 | |
Percent of CPU this job got: 91% | |
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:03.50 | |
Average shared text size (kbytes): 0 | |
Average unshared data size (kbytes): 0 | |
Average stack size (kbytes): 0 | |
Average total size (kbytes): 0 | |
Maximum resident set size (kbytes): 2156 | |
Average resident set size (kbytes): 0 | |
Major (requiring I/O) page faults: 0 | |
Minor (reclaiming a frame) page faults: 588 | |
Voluntary context switches: 1 | |
Involuntary context switches: 1231 | |
Swaps: 0 | |
File system inputs: 0 | |
File system outputs: 0 | |
Socket messages sent: 0 | |
Socket messages received: 0 | |
Signals delivered: 0 | |
Page size (bytes): 4096 | |
Exit status: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment