<commit_before>package org.scalameter
package execution



import java.io._
import collection._
import sys.process._
import utils.Tree



/** Runs multiple JVM instances per each setup and aggregates all the results together.
 *
 *  This produces more stable results, as the performance related effects of each JVM instantiation
 *  are averaged.
 */
class SeparateJvmsExecutor(val warmer: Executor.Warmer, val aggregator: Aggregator, val measurer: Executor.Measurer) extends Executor {

  import Key._

  val runner = new JvmRunner

  def runSetup[T](setup: Setup[T]): CurveData = {
    import setup._

    val warmups = context.goe(exec.maxWarmupRuns, 10)
    val totalreps = context.goe(exec.benchRuns, 10)
    val independentSamples = context.goe(exec.independentSamples, 9)
    def repetitions(idx: Int): Int = {
      val is = independentSamples
      totalreps / is + (if (idx < totalreps % is) 1 else 0)
    }

    val m = measurer
    val w = warmer
    val jvmContext = createJvmContext(context)

    def sample(idx: Int, reps: Int): Seq[(Parameters, Seq[Double])] = runner.run(jvmContext) {
      dyn.initialContext.value = context
      
      log.verbose(s"Sampling $reps measurements in separate JVM invocation $idx - ${context.scope}, ${context.goe(dsl.curve, "")}.")

      // warmup
      setupBeforeAll()
      customwarmup match {
        case Some(warmup) =>
          for (i <- 0 until warmups) warmup()
        case _ =>
          for (x <- gen.warmupset) {
            for (i <- w.warming(context, setupFor(x), teardownFor(x))) snippet(x)
          }
      }
      teardownAfterAll()

      // perform GC
      compat.Platform.collectGarbage()

      // measure
      setupBeforeAll()
      val observations = for (params <- gen.dataset) yield {
        val set = setupFor()
        val tear = teardownFor()
        val regen = regenerateFor(params)
        (params, m.measure(context, reps, set, tear, regen, snippet))
      }
      teardownAfterAll()

      observations.toBuffer
    }

    def sampleReport(idx: Int, reps: Int): Seq[(Parameters, Seq[Double])] = try {
      sample(idx, reps)
    } catch {
      case e: Exception =>
        log.error(s"Error running separate JVM: $e")<commit_msg>cleanup after SeparateJvmsExecutor properly<commit_after>package org.scalameter
package execution



import java.io._
import collection._
import sys.process._
import utils.Tree



/** Runs multiple JVM instances per each setup and aggregates all the results together.
 *
 *  This produces more stable results, as the performance related effects of each JVM instantiation
 *  are averaged.
 */
class SeparateJvmsExecutor(val warmer: Executor.Warmer, val aggregator: Aggregator, val measurer: Executor.Measurer) extends Executor {

  import Key._

  val runner = new JvmRunner

  def runSetup[T](setup: Setup[T]): CurveData = {
    import setup._

    val warmups = context.goe(exec.maxWarmupRuns, 10)
    val totalreps = context.goe(exec.benchRuns, 10)
    val independentSamples = context.goe(exec.independentSamples, 9)
    def repetitions(idx: Int): Int = {
      val is = independentSamples
      totalreps / is + (if (idx < totalreps % is) 1 else 0)
    }

    val m = measurer
    val w = warmer
    val jvmContext = createJvmContext(context)

    def sample(idx: Int, reps: Int): Seq[(Parameters, Seq[Double])] = runner.run(jvmContext) {
      dyn.initialContext.value = context
      
      log.verbose(s"Sampling $reps measurements in separate JVM invocation $idx - ${context.scope}, ${context.goe(dsl.curve, "")}.")

      // warmup
      setupBeforeAll()
      customwarmup match {
        case Some(warmup) =>
          for (i <- 0 until warmups) warmup()
        case _ =>
          for (x <- gen.warmupset) {
            for (i <- w.warming(context, setupFor(x), teardownFor(x))) snippet(x)
          }
      }
      teardownAfterAll()

      // perform GC
      compat.Platform.collectGarbage()

      // measure
      setupBeforeAll()
      val observations = new mutable.ArrayBuffer[(Parameters, Seq[Double])]()
      for (params <- gen.dataset) {
        val set = setupFor()
        val tear = teardownFor()
        val regen = regenerateFor(params)
        observations += (params -> m.measure(context, reps, set, tear, regen, snippet))
      }
      teardownAfterAll()

      observations
    }

    def sampleReport(idx: Int, reps: Int): Seq[(Parameters, Seq[Double])] = try {
      sample(idx, reps)
    } catch {
      case e: Exception =>
        log.error(s"Error running separate JVM: $e")
{'fraction_non_alphanumeric': 0.10929925077126487, 'fraction_numerical': 0.0035257822829440283, 'mean_word_length': 2.763681592039801, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, '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': '2276680', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1355, 'n_words': 391}