code: def benchmark_run(
      ctx,
      rev_or_path,
      src,
      preserve,
      output,
      cmake_extras,
      java_home,
      java_options,
      build_extras,
      benchmark_extras,
      language,
      suite_filter,
      benchmark_filter,
      repetitions,
      repetition_min_time,
      cpp_benchmark_extras,
      **kwargs,
  ):
      """Run benchmark suite.
  
      This command will run the benchmark suite for a single build. This is
      used to capture (and/or publish) the results.
  
      The caller can optionally specify a target which is either a git revision
      (commit, tag, special values like HEAD) or a cmake build directory.
  
      When a commit is referenced, a local clone of the arrow sources (specified
      via --src) is performed and the proper branch is created. This is done in
      a temporary directory which can be left intact with the `--preserve` flag.
  
      The special token "WORKSPACE" is reserved to specify the current git
      workspace. This imply that no clone will be performed.
  
      Examples:
  
      \b
      # Run the benchmarks on current git workspace
      \b
      archery benchmark run
  
      \b
      # Run the benchmarks on an existing build directory
      \b
      archery benchmark run /build/cpp
  
      \b
      # Run the benchmarks on current previous commit
      \b
      archery benchmark run HEAD~1
  
      \b
      # Run the benchmarks on current git workspace and output results as a JSON file.
      \b
      archery benchmark run --output=run.json
      """
      with tmpdir(preserve=preserve) as root:
          logger.debug("Running benchmark {}".format(rev_or_path))
  
          if language == "cpp":
              conf = CppBenchmarkRunner.default_configuration(
                  cmake_extras=cmake_extras, **kwargs
              )
  
              repetitions = repetitions if repetitions != -1 else 1
              runner_base = CppBenchmarkRunner.from_rev_or_path(
                  src,
                  root,
                  rev_or_path,
                  conf,
                  repetitions=repetitions,
                  repetition_min_time=repetition_min_time,
                  suite_filter=suite_filter,
                  benchmark_filter=benchmark_filter,
                  benchmark_extras=cpp_benchmark_extras,
              )
  
          elif language == "java":
              for key in {
                  "cpp_package_prefix",
                  "cxx_flags",
                  "cxx",
                  "cc",
              }:
                  del kwargs[key]
              conf = JavaBenchmarkRunner.default_configuration(
                  java_home=java_home,
                  java_options=java_options,
                  build_extras=build_extras,
                  benchmark_extras=benchmark_extras,
                  **kwargs,
              )
  
              repetitions = repetitions if repetitions != -1 else 5
              runner_base = JavaBenchmarkRunner.from_rev_or_path(
                  src,
                  root,
                  rev_or_path,
                  conf,
                  repetitions=repetitions,
                  benchmark_filter=benchmark_filter,
              )
  
          # XXX for some reason, the benchmark runner only does its work
          # when asked to JSON-serialize the results, so produce a JSON
          # output even when none is requested.
          json_out = json.dumps(runner_base, cls=JsonEncoder)
          if output is not None:
              output.write(json_out)
  
imports: from collections import namedtuple
  from io import StringIO
  import click
  import json
  import logging
  import os
  import pathlib
  import sys
  from .benchmark.codec import JsonEncoder
  from .benchmark.compare import RunnerComparator, DEFAULT_THRESHOLD
  from .benchmark.runner import CppBenchmarkRunner, JavaBenchmarkRunner
  from .compat import _import_pandas
  from .lang.cpp import CppCMakeDefinition, CppConfiguration
  from .utils.cli import ArrowBool, validate_arrow_sources, add_optional_command
  from .utils.lint import linter, python_numpydoc, LintValidationException
  from .utils.logger import logger, ctx
  from .utils.source import ArrowSources
  from .utils.tmpdir import tmpdir
label_desc: Use image node_id 14 for calling a global function with example usage: benchmark_run(ctx, rev_or_path, src, preserve, output, cmake_extras, java_home, java_options, build_extras, benchmark_extras, language, suite_filter, benchmark_filter, repetitions, repetition_min_time, cpp_benchmark_extras) without return types