Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.collection.mutable.ArrayBuffer
- import scala.annotation.tailrec
- import scala.collection.mutable.ListBuffer
- //import org.apache.commons.lang3.StringUtils
- object Test
- {
- def split(s: String, c: Char, i: Int = 0): List[String] = if (i < 0) Nil else {
- val p = s indexOf (c, i)
- if (p < 0) s.substring(i) :: Nil else s.substring(i, p) :: split(s, c, p + 1)
- }
- def split2(s: String, c: Char): Seq[String] = {
- val buffer = ListBuffer.empty[String]
- @tailrec def recurse(i: Int): Seq[String] = {
- val p = s indexOf (c, i)
- if (p < 0) {
- buffer += s.substring(i)
- buffer.toList
- } else {
- buffer += s.substring(i, p)
- recurse(p + 1)
- }
- }
- recurse(0)
- }
- def main(args: Array[String])
- {
- var len = 0
- val t1 = System.currentTimeMillis()
- io.Source.fromFile(args(0)).getLines.foreach { line =>
- val s_line = line.split('\t')
- len += line.length
- }
- val t2 = System.currentTimeMillis()
- val s1 = (t2-t1)/1000.0
- var mb_s = (len/(1024.0*1024.0))/s1
- println(mb_s + " MB/s - Scala split('\\t')")
- len = 0
- val t3 = System.currentTimeMillis()
- io.Source.fromFile(args(0)).getLines.foreach { line =>
- val s_line = line.split("\t")
- len += line.length
- }
- val t4 = System.currentTimeMillis()
- val s2 = (t4-t3)/1000.0
- mb_s = (len/(1024.0*1024.0))/s2
- println(mb_s + " MB/s - Scala split(\"\\t\")")
- len = 0
- val t5 = System.currentTimeMillis()
- io.Source.fromFile(args(0)).getLines.foreach { line =>
- val s_line = split(line, '\t')
- len += line.length
- }
- val t6 = System.currentTimeMillis()
- val s3 = (t6-t5)/1000.0
- mb_s = (len/(1024.0*1024.0))/s3
- println(mb_s + " MB/s - dcsobralWork-1")
- len = -1
- val t7 = System.currentTimeMillis()
- io.Source.fromFile(args(0)).getLines.foreach { line =>
- val s_line = split2(line, '\t')
- len += line.length
- }
- val t8 = System.currentTimeMillis()
- val s4 = (t8-t7)/1000.0
- mb_s = (len/(1024.0*1024.0))/s4
- println(mb_s + " MB/s - dcsobralWork-2")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement