I have made some benchmarking tests on writing 2000 bytes array and surprised with results
[info] benchmark us linear runtime
[info] _writeIO 58.8 =
[info] _writeIOBulk 191834.4 =========
[info] _writeIOBulk2 604051.9 ==============================
[info] _writeIOJava 99.9 =
I am making some calculation on SA array and write the transformation to file "fname" acording following methods.
But why _writeIOBulk2 is slower as _writeIOBulk and _writeIOJava is 2x slower as _writeIO i cant understand . And anyway what is the fastest and cleanest way to make this operation :
acording some Iterated object write anther Iterated object in file .
var SA = new Array[Int](n)
var chr = new Array[Byte](n)
def writeIOJava(fname:String):Unit = {
var output = new java.io.FileOutputStream(fname)
val bwt= new Array[Byte](n)
for ( i<- 0 until n) {
val pIdx = SA(i)-1
bwt(i) = chr(if (pIdx >= 0) pIdx else pIdx+n ).toByte
}
output.write(bwt)
output.close()
}
def writeIO(fname:String):Unit = {
val output:Output = Resource.fromFile(fname)
val bwt= new Array[Byte](n)
for ( i<- 0 until n) {
val pIdx = SA(i)-1
bwt(i) = chr(if (pIdx >= 0) pIdx else pIdx+n ).toByte
}
output.write(bwt)
}
def writeIOBulk(fname:String):Unit = {
val output:Output = Resource.fromFile(fname)
//val bwt= new Array[Byte](n)
for ( i<- 0 until n) {
val pIdx = SA(i)-1
output.write(chr(if (pIdx >= 0) pIdx else pIdx+n ).toByte)
}
}
def writeIOBulk2(fname:String):Unit = {
val output = Path.fromString(fname).outputStream(WriteTruncate:_*)
//val bwt= new Array[Byte](n)
for ( i<- 0 until n) {
val pIdx = SA(i)-1
output.write(chr(if (pIdx >= 0) pIdx else pIdx+n ).toByte)
}
}