I saw the following code (http://www.samuelbosch.com/2014/07/benchmarking-reading-binary-values-from.html) and I was intrigued how close the structure resembles Scheme or Lisp code (I wrote something similar in Bigloo 20 years ago):
function readvalue(stream, position)
seek(stream, position)
return read(stream, Int32)
end
function readvalues(filename::String, indices)
stream = open(filename, "r")
try
return Int32[readvalue(stream, index*4) for index in indices]
finally
close(stream)
end
end
The Julia code performed worst in the test (compared to Python, Go language, F#, Ocaml, with the exception of R). I am not concerned with the Julia performance but wonder what needs to be changed to make the above code Julia idiomatic?
By the way: I was also intrigued by the F# version:
open System
open System.IO
let readValue (reader:BinaryReader) cellIndex =
reader.BaseStream.Seek(int64 (cellIndex*4), SeekOrigin.Begin) ignore
match reader.ReadInt32() with
| Int32.MinValue -> None
| v -> Some(v)
let readValues indices fileName =
use reader = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
let values = Array.map (readValue reader) indices
values