Created
November 5, 2013 11:19
-
-
Save goldeneggg/7317600 to your computer and use it in GitHub Desktop.
二重引用符付きCSVを処理するとして、str.split(",")した後のクォーテーション除去を map(_.replace("¥"")) と map(_.init.tail) で速度比較したら後者の方が速かった (20回ずつ動かして比較) #scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Hoge { | |
def main(args: Array[String]) { | |
for (i <- (1 to 20)) mainRecur(args(0).toInt) | |
} | |
private def mainRecur(ver: Int) { | |
var start = System.nanoTime | |
val s = "\"1\",\"22\",\"333\",\"4444\",\"55555\"" | |
val ss = s.split(",") | |
val l = if (ver == 1) verReplace(ss) else verInitTail(ss) | |
var end = System.nanoTime | |
var sec = (end - start) | |
println("Done. Total nano sec: %d".format(sec)) | |
} | |
private def verReplace(ss: Array[String]) = { | |
ss map { _.replace("\"", "") } | |
} | |
private def verInitTail(ss: Array[String]) = { | |
ss map { _.init.tail } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace版
init.tail版