Skip to content

Instantly share code, notes, and snippets.

@catawbasam
Created March 5, 2014 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catawbasam/9364944 to your computer and use it in GitHub Desktop.
Save catawbasam/9364944 to your computer and use it in GitHub Desktop.
Update to Julia word count test
# 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