Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writting individual bytes is very slow #87

Open
jesseeichar opened this issue Jun 4, 2013 · 0 comments
Open

Writting individual bytes is very slow #87

jesseeichar opened this issue Jun 4, 2013 · 0 comments

Comments

@jesseeichar
Copy link
Owner

[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 ArrayInt
var chr = new ArrayByte

def writeIOJava(fname:String):Unit = {
var output = new java.io.FileOutputStream(fname)
val bwt= new ArrayByte
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 ArrayByte
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 ArrayByte
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 ArrayByte
for ( i<- 0 until n) {
val pIdx = SA(i)-1
output.write(chr(if (pIdx >= 0) pIdx else pIdx+n ).toByte)
}
}

@ghost ghost assigned jesseeichar Jun 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant