Last active
January 3, 2016 04:59
-
-
Save jfsantos/8412953 to your computer and use it in GitHub Desktop.
Julia answer to text benchmarks (http://matthewrocklin.com/blog/work/2014/01/13/Text-Benchmarks/)
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
function groupby{T}(fn::Function, seq::Array{T}) | |
dict = Dict{Any, Array{T}}(); | |
for item in seq | |
key = fn(item); | |
if !haskey(dict, key) | |
dict[key] = []; | |
end | |
push!(dict[key], item); | |
end | |
return dict; | |
end | |
function processdata(file::String) | |
filename = ARGS[1]; | |
file = open(filename); | |
lines = readlines(file); | |
#lines = convert(Array{String, 1}, map(strip, lines)); | |
lines = map(strip, lines) | |
word_pairs = map(s->split(s, ','), lines); | |
result = groupby(a->a[1], word_pairs); | |
end | |
processdata("test.txt") | |
@time begin | |
result = processdata(ARGS[1]); | |
end |
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
it, was | |
was, the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment