I was trying to improve the Julia score on the next basic benchmark https://github.com/Microbiology/JuliaPerlBenchmark (where they conclude that Perl is faster than Julia for processing fasta files).
I already spotted one error in the benchmark: The data file used was not big enough to provide data for the larger benchmarks. After correcting this, Julia is clearly faster than Perl for larger files (Go is stil a lot faster though), but slowest for smaller files. This is due to the quite significant start-up/compilation time (0.6 seconds on my system for one small function) of the Julia version.
As in many of my workflows I would need to run commands implemented in Julia (rather than opening a repl and giving the commands), I tried making the benchmark into a module and apply precompilation to remove/reduce the startup cost:
__precompile__() module Medlength export medlength function medlength(file) open(file, "r") do fasta_in length_array = Int seq_length = -1 for line in eachline(fasta_in) if startswith(line,'>') if seq_length != -1 push!(length_array, seq_length) end seq_length = 0 else seq_length += length(chomp(line)) end end if seq_length != -1 push!(length_array, seq_length) end println(median(length_array)) end end precompile(medlength,(String,)) end
On first run the module seems to be precompiled to the cache (message, precompiling to a cache does take a lot longer than normal startup,> 1 second).
However, on subsequent runs the program using the module is not faster at all; the startup still takes 0.6 seconds …
Is there something wrong still with the module definition?
In searching for solutions, I read somewhere that precompilation only does the parsing and does not compile to machine code. Is this correct?
If it is, can this be changed? It seems that precompiling to machine code should be possible for a local cache.
Finally, if solved for modules, would it be feasible to precompile/cache functions in scripts (not modules)? (to avoid potential users doing the typical small benchmark script and concluding that Julia is slow)