package tabulate.benchmark

import java.io.{StringWriter, Writer}
import java.util.concurrent.TimeUnit

import org.apache.commons.csv.CSVFormat
import org.openjdk.jmh.annotations._
import tabulate.ops._

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class EncodingBenchmark {
  def write[A](f: Array[String] => Unit): Unit =
    rawData.foreach { entry => f(Array(entry._1.toString, entry._2.toString, entry._3.toString, entry._4.toString)) }

  @Benchmark
  def tabulate() = new StringWriter().writeCsv(rawData, ',').close()

  @Benchmark
  def productCollections() = {
    val out = new StringWriter()
    com.github.marklister.collections.io.Utils.CsvOutput(rawData).writeCsv(out, ",")
    out.close()
  }

  @Benchmark
  def opencsv() = {
    val out = new StringWriter()
    val writer = new com.opencsv.CSVWriter(out, ',')
    write { a => writer.writeNext(a) }
    writer.close()
    out.close()
  }

  @Benchmark
  def commonsCsv() = {
    val out = new StringWriter()
    val writer = new org.apache.commons.csv.CSVPrinter(out, CSVFormat.RFC4180)
    write { a => writer.printRecords(a) }
    writer.close()
    out.close()
  }
}

package tabulate.benchmark

import java.io.{StringWriter, Writer}
import java.util.concurrent.TimeUnit

import org.openjdk.jmh.annotations._
import tabulate.ops._

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class EncodingBenchmark {
  def write[A](f: Array[String] => Unit): Unit =
    rawData.foreach { entry => f(Array(entry._1.toString, entry._2.toString, entry._3.toString, entry._4.toString)) }

  @Benchmark
  def tabulate() = new StringWriter().writeCsv(rawData, ',').close()

  @Benchmark
  def productCollections() = {
    val out = new StringWriter()
    com.github.marklister.collections.io.Utils.CsvOutput(rawData).writeCsv(out, ",")
    out.close()
  }

  @Benchmark
  def opencsv() = {
    val out = new StringWriter()
    val writer = new com.opencsv.CSVWriter(out, ',')
    write { a => writer.writeNext(a) }
    writer.close()
    out.close()
  }
}

--- 
+++ 
@@ -3,6 +3,7 @@
 import java.io.{StringWriter, Writer}
 import java.util.concurrent.TimeUnit
 
+import org.apache.commons.csv.CSVFormat
 import org.openjdk.jmh.annotations._
 import tabulate.ops._
 
@@ -31,4 +32,13 @@
     writer.close()
     out.close()
   }
+
+  @Benchmark
+  def commonsCsv() = {
+    val out = new StringWriter()
+    val writer = new org.apache.commons.csv.CSVPrinter(out, CSVFormat.RFC4180)
+    write { a => writer.printRecords(a) }
+    writer.close()
+    out.close()
+  }
 }
Add commons-csv to the various libraries benchmarked for writing.
