Created
April 29, 2014 04:44
-
-
Save anonymous/11390832 to your computer and use it in GitHub Desktop.
split in ruby
This file contains hidden or 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
results from time: | |
# ruby | |
% time ruby split.rb | |
real 1m18.252s | |
user 1m16.855s | |
sys 0m0.979s | |
============= | |
# nimrod | |
% time ./split | |
real 2m39.531s | |
user 2m38.931s | |
sys 0m0.480s | |
# c | |
% time ./splitter | |
real 0m13.872s | |
user 0m13.562s | |
sys 0m0.300s |
This file contains hidden or 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
import strutils | |
let fn = "junkdata.txt" | |
for line in lines(fn): | |
let | |
ln = line.split("\t") | |
data1 = ln[0] | |
data2 = ln[1] |
This file contains hidden or 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/env ruby | |
# create file if not exist. | |
fn = "junkdata.txt" | |
if not File.exist?(fn) | |
File.open("junkdata.txt","w") do |f| | |
100_000_000.times { f.puts "this is data field number1\tV" } | |
end | |
puts "file created. run again to parse. exitting" | |
exit | |
end | |
File.open(fn,"rb").each do |line| | |
line.chomp! | |
data1,data2 = line.split("\t") | |
end |
This file contains hidden or 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
#include <stdio.h> | |
int main() { | |
char data1[70]; | |
char data2[2]; | |
char line[100]; | |
int j = 0; | |
FILE *fp = fopen("junkdata.txt", "rb"); | |
if (!fp) { | |
printf("Couldn't open file for reading\n"); | |
return 0; | |
} | |
while(fgets(line, 99, fp) != NULL){ | |
sscanf(line, "%s\t%s\n", data1, data2); | |
j++; | |
/* | |
if(0 && j < 100) { | |
printf("%d) %s -> %s\n", j,data1,data2); | |
} | |
*/ | |
} | |
printf("%d\n",j); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment