I don’t think you pushed anything, but if I fix the printing I get
Benchmarking...
===> java -cp build/java Main
Proc,Memory(bytes),Time(ms)
java,0,308
Proc,Memory(bytes),Time(ms)
java,0,390
Proc,Memory(bytes),Time(ms)
java,0,591
Proc,Memory(bytes),Time(ms)
java,0,828
===> java -cp build/java Main2
Proc,Memory(bytes),Time(ms)
java,0,336
Proc,Memory(bytes),Time(ms)
java,0,545
Proc,Memory(bytes),Time(ms)
java,0,1798
Proc,Memory(bytes),Time(ms)
java,0,1907
===> ./phone_encoder
Proc,Memory(bytes),Time(ms)
./phone_encoder,0,127
Proc,Memory(bytes),Time(ms)
./phone_encoder,0,263
Proc,Memory(bytes),Time(ms)
./phone_encoder,0,802
Proc,Memory(bytes),Time(ms)
./phone_encoder,0,1711
===> j1 src/julia/phone_encoder.jl
Proc,Memory(bytes),Time(ms)
j1,0,2043
Proc,Memory(bytes),Time(ms)
j1,0,2831
Proc,Memory(bytes),Time(ms)
j1,0,6398
Proc,Memory(bytes),Time(ms)
j1,0,8082
===> j1 src/julia/phone_encoder_pfitzseb.jl
Proc,Memory(bytes),Time(ms)
j1,0,703
Proc,Memory(bytes),Time(ms)
j1,0,773
Proc,Memory(bytes),Time(ms)
j1,0,1155
Proc,Memory(bytes),Time(ms)
j1,0,1664
===> j1 src/julia/phone_encoder_jakni.jl
Proc,Memory(bytes),Time(ms)
j1,0,1074
Proc,Memory(bytes),Time(ms)
j1,0,1153
Proc,Memory(bytes),Time(ms)
j1,0,1496
Proc,Memory(bytes),Time(ms)
j1,0,1896
Oh, and here is my version (just realized I hadn’t posted that anywhere):
Replaced BigInt usage with two Int128s, optimized printing:
#=
# Port of Peter Norvig's Common Lisp program from http://norvig.com/java-lisp.html.
#
# - Julia version: 1.6.2
# - Author: Renato Athaydes
# - Date: 2021-07-24
=#
const emptyStrings = String[]
function printTranslations(dict, num, digits, start=1, words=String[])
if start > length(digits)
print(num, ": ")
for (i, word) in enumerate(words)
print(word)
i == length(words) ? println() : print(' ')
end
return
end
foundWord = false
n1, n2 = Int128(0), Int128(1)
for i in start:length(digits)
if n2 >= 1e25
n1 = n1 * 10 + nthDigit(digits, i)
else
n2 = n2 * 10 + nthDigit(digits, i)
end
for word in get(dict, (n1, n2), emptyStrings)
foundWord = true
push!(words, word)
printTranslations(dict, num, digits, i + 1, words)
pop!(words)
end
end
if !foundWord &&
!(!isempty(words) && length(words[end]) == 1 && isdigit(words[end][begin]))
push!(words, string(nthDigit(digits, start)))
printTranslations(dict, num, digits, start + 1, words)
pop!(words)
end
end
function loadDictionary(file)::Dict{Tuple{Int128, Int128}, Vector{String}}
local dict = Dict{Tuple{Int128, Int128}, Vector{String}}()
for word in eachline(file)
push!(get!(() -> String[], dict, wordToNumber(word)), word)
end
dict
end
function nthDigit(digits::String, i::Int64)::UInt
UInt(digits[i]) - UInt('0')
end
function charToDigit(ch::Char)::UInt
ch = lowercase(ch)
ch == 'e' && return 0
ch in ('j', 'n', 'q') && return 1
ch in ('r', 'w', 'x') && return 2
ch in ('d', 's', 'y') && return 3
ch in ('f', 't') && return 4
ch in ('a', 'm') && return 5
ch in ('c', 'i', 'v') && return 6
ch in ('b', 'k', 'u') && return 7
ch in ('l', 'o', 'p') && return 8
ch in ('g', 'h', 'z') && return 9
throw(DomainError(ch, "Not a letter"))
end
function wordToNumber(word::String)::Tuple{Int128, Int128}
n1, n2 = Int128(0), Int128(1)
for ch in word
if isletter(ch) && isascii(ch)
if n2 >= 1e25
n1 = n1 * 10 + charToDigit(ch)
else
n2 = n2 * 10 + charToDigit(ch)
end
end
end
n1, n2
end
function main(dictionary, input)
dict = open(dictionary) do file
loadDictionary(file)
end
open(input) do file
for num in eachline(file)
printTranslations(dict, num, filter(isdigit, num))
end
end
end
if length(ARGS) == 2
main(ARGS...)
end