代码之家  ›  专栏  ›  技术社区  ›  Abhijit Sarkar

如何使用文件中的数据进行微标记?

  •  0
  • Abhijit Sarkar  · 技术社区  · 6 年前

    我正在尝试微基准化两种不同的计算运行中值的方法 Scalameter . 我有一些测试文件,小的和大的,从哪里来的数字。问题是,以下代码立即完成,根本不生成任何类型的基准。

    object MedianMaintenanceBenchmark extends Bench[Double] {
    
      /* configuration */
    
      lazy val executor = LocalExecutor(
        new Warmer.Default,
        Aggregator.median[Double],
        measurer
      )
      lazy val measurer = new Measurer.Default
      lazy val reporter = new LoggingReporter[Double]
      lazy val persistor: Persistor.None.type = Persistor.None
    
      /* inputs */
    
      private val files: Gen[String] = Gen.enumeration("files")("median-test")
      private val num: Gen[Seq[Int]] = (for (f <- files) yield numbers(f)).cached
    
      /* tests */
    
      performance of "MedianMaintenance" config (
        exec.benchRuns -> 10
        ) in {
        measure method "using heap" in {
          using(num) in {
            xs => MedianMaintenanceUsingHeaps(xs).medians
          }
        }
      }
    
      private def numbers(filename: String): Seq[Int] = // elided
    }
    

    输出:

    ::Benchmark MedianMaintenance.using heap::
    cores: 8
    hostname: ***
    name: OpenJDK 64-Bit Server VM
    osArch: x86_64
    osName: Mac OS X
    vendor: Azul Systems, Inc.
    version: 11.0.1+13-LTS
    Parameters(files -> median-test): 3.612799 ms
    

    这是怎么回事?

    编辑:

    按照下面的方式更改代码至少可以做一些事情,但不符合选项的要求。对于文件“中位数”,它似乎总共运行了18次测试,这不是3+10的总和。

    object MedianMaintenanceBenchmark extends Bench.ForkedTime {
    
      /* configuration */
      override def aggregator: Aggregator[Double] = Aggregator.median
    
      private val opts = Context(
        exec.minWarmupRuns-> 3,
        exec.maxWarmupRuns -> 3,
        exec.benchRuns -> 10,
        exec.jvmflags -> List("-Xms2g", "-Xmx2g")
      )
    
      /* inputs */
    
      private val files: Gen[String] = Gen.enumeration("files")("median-test", "Median")
      private val num: Gen[Seq[Int]] = (for (f <- files) yield numbers(f)).cached
    
      /* tests */
    
      performance of "MedianMaintenance" config opts in {
        measure method "using heap" in {
          using(num) in {
            xs => MedianMaintenanceUsingHeaps(xs).medians
          }
        }
    
        measure method "using red-black BST" in {
          using(num) in {
            xs => MedianMaintenanceUsingRedBlackTree(xs).medians
          }
        }
      }
    
      private def numbers(filename: String): Seq[Int] = // elided
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Abhijit Sarkar    6 年前

    这里的操作:几个小时后,我终于能够读完那些过时的文档,不管怎么说,这些文档都已经过时了,并找到了以下内容:

    除了上面的编辑,还有几种方法可以覆盖执行计数等。

    1. 对于当前文件中的所有基准,使用 override def defaultConfig: Context = Context(exec.benchRuns -> 10)
    2. 对于特定的基准,定义inline或 val opts: Context 和使用 config opts in DSL。
    3. 对于特定的方法,请执行与2相同的操作,除非使用 配置在 方法DSL。
    4. 文档声称可以覆盖每个“曲线”的配置,但我无法找到“曲线”是什么,也无法找到如何覆盖它的配置。

    IndependentSamples=生成的独立JVM数。

    热身运动 (minWarmupRuns to maxWarmupRuns) 使用一组测试数据(随机选取?)在每个JVM上的时间(有意义),然后在每个JVM上为 benchRuns 时代。 运行多少预热取决于“稳态”的检测。对于每个JVM,似乎最终都有一次执行未被计算在内。

    Total number of executions = independentSamples * ((minWarmupRuns to maxWarmupRuns) + benchRuns + 1)
    

    例如,假设:

    Context(
      exec.minWarmupRuns -> 5,
      exec.maxWarmupRuns -> 5,
      exec.benchRuns -> 10,
      exec.independentSamples -> 2
    )
    

    将有32个正在测试的代码执行。

    推荐文章