<commit_before>package tabulate.benchmark

import java.io.StringWriter
import java.util.concurrent.TimeUnit

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

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class Encoding {
  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 tabulateInternal() = rawData.asCsvString(',')

  @Benchmark
  def tabulateJackson() = {
    import tabulate.engine.jackson._
    rawData.asCsvString(',')
  }

  @Benchmark
  def tabulateOpencsv() = {
    import tabulate.engine.opencsv._
    rawData.asCsvString(',')
  }

  @Benchmark
  def tabulateCommons() = {
    import tabulate.engine.commons._
    rawData.asCsvString(',')
  }

  @Benchmark
  def productCollections() = {
    val out = new StringWriter()<commit_msg>Clean-up encoding benchmarks somewhat.<commit_after>package tabulate.benchmark

import java.io.StringWriter
import java.util.concurrent.TimeUnit

import org.apache.commons.csv.CSVFormat
import org.openjdk.jmh.annotations._
import tabulate.engine.WriterEngine
import tabulate.engine.jackson.JacksonCsv
import tabulate.ops._

@State(Scope.Thread)
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class Encoding {
  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)) }

  def tabulateEngine(implicit engine: WriterEngine) = rawData.asCsvString(',')

  @Benchmark
  def tabulateInternal() = tabulateEngine

  @Benchmark
  def tabulateJackson() = tabulateEngine(tabulate.engine.jackson.engine)

  @Benchmark
  def tabulateOpencsv() = tabulateEngine(tabulate.engine.opencsv.engine)

  @Benchmark
  def tabulateCommons() = tabulateEngine(tabulate.engine.commons.engine)

  @Benchmark
  def productCollections() = {
    val out = new StringWriter()
{'fraction_non_alphanumeric': 0.11954459203036052, 'fraction_numerical': 0.003795066413662239, 'mean_word_length': 4.9914772727272725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4227469', 'n_tokens_mistral': 720, 'n_tokens_neox': 693, 'n_words': 121}