<commit_before>/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala.testing

import compat.Platform

/** `Benchmark` can be used to quickly turn an existing class into a
 *  benchmark. Here is a short example:
 *  {{{
 *  object sort1 extends Sorter with Benchmark {
 *    def run = sort(List.range(1, 1000))
 *  }
 *  }}}
 *  The `run` method has to be defined by the user, who will perform the
 *  timed operation there. Run the benchmark as follows:
 *  {{{
 *  > scala sort1 5
 *  }}}
 *  This will run the benchmark 5 times, forcing a garbage collection
 *  between runs, and printing the execution times to stdout.
 *
 *  It is also possible to add a multiplier, so
 *  {{{
 *  > scala sort1 5 10
 *  }}}
 *  will run the entire benchmark 10 times, each time for 5 runs.
 *
 *  @author <NAME>, <NAME>
 */
trait Benchmark {

  /** this method should be implemented by the concrete benchmark.
   *  This method is called by the benchmarking code for a number of times.
   *  The GC is called before each call to 'run'.
   *
   *  @see setUp
   *  @see tearDown
   */
  def run()

  var multiplier = 1

  /** Run the benchmark the specified number of times and return a list with
   *  the execution times in milliseconds in reverse order of the execution.
   *
   *  @param noTimes ...
   *  @return        ...
   */
  def runBenchmark(noTimes: Int): List[Long] =
    for (i <- List.range(1, noTimes + 1)) yield {
      setUp
      val startTime = Platform.currentTime
      var i = 0; while (i < multiplier) {
        run()
        i += 1
      }<commit_msg>Improves Benchmark documentation.<commit_after>/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala.testing

import compat.Platform

/** `Benchmark` can be used to quickly turn an existing class into a
 *  benchmark. Here is a short example:
 *  {{{
 *  object sort1 extends Sorter with Benchmark {
 *    def run = sort(List.range(1, 1000))
 *  }
 *  }}}
 *  The `run` method has to be defined by the user, who will perform the
 *  timed operation there. Run the benchmark as follows:
 *  {{{
 *  > scala sort1 5
 *  }}}
 *  This will run the benchmark 5 times, forcing a garbage collection
 *  between runs, and printing the execution times to stdout.
 *
 *  It is also possible to add a multiplier, so
 *  {{{
 *  > scala sort1 5 10
 *  }}}
 *  will run the entire benchmark 10 times, each time for 5 runs.
 *
 *  @author <NAME>, <NAME>
 */
trait Benchmark {

  /** this method should be implemented by the concrete benchmark.
   *  This method is called by the benchmarking code for a number of times.
   *  The GC is called between "multiplier" calls to run, right after tear
   *  down.
   *
   *  @see setUp
   *  @see tearDown
   */
  def run()

  var multiplier = 1

  /** Run the benchmark the specified number of times and return a list with
   *  the execution times in milliseconds in reverse order of the execution.
   *
   *  @param noTimes ...
   *  @return        ...
   */
  def runBenchmark(noTimes: Int): List[Long] =
    for (i <- List.range(1, noTimes + 1)) yield {
      setUp
      val startTime = Platform.currentTime
      var i = 0; while (i < multiplier) {
        run()
        i += 1
      }
{'fraction_non_alphanumeric': 0.10801058455617031, 'fraction_numerical': 0.013952369497233582, 'mean_word_length': 1.4705882352941178, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5819303', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1154, 'n_words': 414}