<commit_before>package com.komanov.serialization.jmh

import java.util.concurrent.TimeUnit

import com.komanov.serialization.converters._
import com.komanov.serialization.converters.api.{EventConverter, SiteConverter}
import com.komanov.serialization.domain.{EventProcessor, Site, SiteEvent}
import org.openjdk.jmh.annotations._

@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(value = 1, jvmArgs = Array("-Xmx2G"))
@Threads(2)
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 2, time = 5, timeUnit = TimeUnit.SECONDS)
abstract class BenchmarkBase

@State(Scope.Benchmark)
class SiteBenchmark extends BenchmarkBase {

  @Param
  var inputType: InputType = _
  @Param
  var converterType: ConverterType = _

  private var converter: SiteConverter = _
  private var input: Site = _
  private var output: Array[Byte] = _

  @Setup
  def setup(): Unit = {
    converter = converterType.converter
    input = inputType.site
    output = converter.toByteArray(input)
  }

  @Benchmark
  def serialization(): Array[Byte] = {
    converter.toByteArray(input)
  }

  @Benchmark
  def deserialization(): Site = {
    converter.fromByteArray(output)
  }

  @Benchmark
  def both(): Site = {
    converter.fromByteArray(converter.toByteArray(inputType.site))
  }
}

@State(Scope.Benchmark)
class EventBenchmark extends BenchmarkBase {

  @Param
  var inputType: InputType = _
  @Param
  var converterType: ConverterType = _

  private var converter: EventConverter = _
  private var input: Seq[SiteEvent] = _
  private var output: Seq[(Class[_], Array[Byte])] = _

  @Setup
  def setup(): Unit = {<commit_msg>Make thread-scope for JMH because of kryo<commit_after>package com.komanov.serialization.jmh

import java.util.concurrent.TimeUnit

import com.komanov.serialization.converters._
import com.komanov.serialization.converters.api.{EventConverter, SiteConverter}
import com.komanov.serialization.domain.{EventProcessor, Site, SiteEvent}
import org.openjdk.jmh.annotations._

@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(value = 1, jvmArgs = Array("-Xmx2G"))
@Threads(2)
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 2, time = 5, timeUnit = TimeUnit.SECONDS)
abstract class BenchmarkBase

@State(Scope.Thread) // Kryo modifies bytes during parsing, see: https://github.com/EsotericSoftware/kryo#threading
class SiteBenchmark extends BenchmarkBase {

  @Param
  var inputType: InputType = _
  @Param
  var converterType: ConverterType = _

  private var converter: SiteConverter = _
  private var input: Site = _
  private var output: Array[Byte] = _

  @Setup
  def setup(): Unit = {
    converter = converterType.converter
    input = inputType.site
    output = converter.toByteArray(input)
  }

  @Benchmark
  def serialization(): Array[Byte] = {
    converter.toByteArray(input)
  }

  @Benchmark
  def deserialization(): Site = {
    converter.fromByteArray(output)
  }

  @Benchmark
  def both(): Site = {
    converter.fromByteArray(converter.toByteArray(inputType.site))
  }
}

@State(Scope.Thread) // Kryo modifies bytes during parsing, see: https://github.com/EsotericSoftware/kryo#threading
class EventBenchmark extends BenchmarkBase {

  @Param
  var inputType: InputType = _
  @Param
  var converterType: ConverterType = _

  private var converter: EventConverter = _
  private var input: Seq[SiteEvent] = _
  private var output: Seq[(Class[_], Array[Byte])] = _

  @Setup
  def setup(): Unit = {
{'fraction_non_alphanumeric': 0.10764474423833614, 'fraction_numerical': 0.0039347948285553686, 'mean_word_length': 4.64920634920635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6990575', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1173, 'n_words': 254}