From 5bb2363eeeeaf22cc8b903366074be9591e1405f Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Fri, 30 Aug 2024 14:23:46 +0200 Subject: [PATCH] mmapped file slightly faster --- src/main/julia/main.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/julia/main.jl b/src/main/julia/main.jl index 44d59c6..5679514 100644 --- a/src/main/julia/main.jl +++ b/src/main/julia/main.jl @@ -36,14 +36,20 @@ end function main() open("../../../measurements.txt", "r") do f println("Start") + sz = Base.stat(f).size + data = mmap(f, Vector{UInt8}, sz) + idxs = findall(isequal(0x0a), data) stations = Dict{String,StationMeasurements}() iteration = 0 - for line in eachline(f) + last_idx = 1 + for i in eachindex(idxs) if iteration % 1000000 == 0 && iteration > 0 print("\x1b[J\x1b[H") percent = round((iteration / 1000000000) * 100; digits=2) println("$(percent)%") end + line = String(data[last_idx:idxs[i]-1]) + last_idx = idxs[i] + 1 station, temp_str = rsplit(line, ";") temp = parse(Float32, temp_str) if haskey(stations, station)