Created
March 5, 2014 10:41
-
-
Save catawbasam/9364944 to your computer and use it in GitHub Desktop.
Update to Julia word count test
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
# Updated Word Count performance test. | |
# | |
# See https://groups.google.com/forum/?fromgroups=#!topic/julia-users/hxfR70Ro-lI | |
using DataStructures | |
import Base.hash | |
hash{T<:ByteString}(s::SubString{T}) = ccall(:memhash, Uint64, (Ptr{Void}, Int), pointer(s), sizeof(s)) | |
fn = "/tmp/juliaV2ydrK" | |
function wordcounter(filename) | |
counts = counter(SubString{UTF8String}) | |
words=split(readall(filename), Set([' ','\n','\r','\t','-','.',',',':','_','"',';','!']),false) | |
for w in words | |
add!(counts,w) | |
end | |
return counts | |
end | |
println("counter on SubString") | |
@time ln = wordcounter(fn); | |
@time ln = wordcounter(fn); | |
@time ln = wordcounter(fn); | |
@time ln = wordcounter(fn); | |
@time ln = wordcounter(fn); | |
function wordcounter_sym(filename) | |
counts = counter(Symbol) | |
words=split(readall(filename), Set([' ','\n','\r','\t','-','.',',',':','_','"',';','!']),false) | |
for w in words | |
add!(counts,symbol(w)) | |
end | |
return counts | |
end | |
println("counter on Symbol") | |
@time ln = wordcounter_sym(fn); | |
@time ln = wordcounter_sym(fn); | |
@time ln = wordcounter_sym(fn); | |
@time ln = wordcounter_sym(fn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment