Git Product home page Git Product logo

criterium's Introduction

Criterium

Criterium measures the computation time of an expression. It is designed to address some of the pitfalls of benchmarking, and benchmarking on the JVM in particular.

This includes:

  • statistical processing of multiple evaluations
  • inclusion of a warm-up period, designed to allow the JIT compiler to optimise its code
  • purging of gc before testing, to isolate timings from GC state prior to testing
  • a final forced GC after testing to estimate impact of cleanup on the timing results

Installation

Leiningen

Add the following to your :dependencies:

[criterium "0.4.5"]

Maven

<dependency>
  <groupId>criterium</groupId>
  <artifactId>criterium</artifactId>
  <version>0.4.5</version>
</dependency>

Usage

The top level interface is in criterium.core.

(use 'criterium.core)

Use bench to run a benchmark in a simple manner.

(bench (Thread/sleep 1000))
 =>
                   Execution time mean : 1.000803 sec
          Execution time std-deviation : 328.501853 us
         Execution time lower quantile : 1.000068 sec ( 2.5%)
         Execution time upper quantile : 1.001186 sec (97.5%)

By default bench is quiet about its progress. Run with-progress-reporting to get progress information on *out*.

(with-progress-reporting (bench (Thread/sleep 1000) :verbose))
(with-progress-reporting (quick-bench (Thread/sleep 1000) :verbose))

Lower level functions are available, that separate benchmark statistic generation and reporting.

(report-result (benchmark (Thread/sleep 1000) {:verbose true}))
(report-result (quick-benchmark (Thread/sleep 1000)))

Note that results are returned to the user to prevent JIT from recognising that the results are not used.

Measurement Overhead Estimation

Criterium will automatically estimate a time for its measurement overhead. The estimate is normally made once per session, and is available in the criterium.core/estimated-overhead-cache var.

If the estimation is made while there is a lot of other processing going on, then benchmarking quick functions may report small negative times. You can force a recalculation of the overhead by calling criterium.core/estimated-overhead!.

If you want consistency across JVM processes, it might be prudent to explicitly set criterium.core/estimated-overhead! to a constant value.

References

API Documentation Annotated Source

See Elliptic Group for a Java benchmarking library. The accompanying article describes many of the JVM benchmarking pitfalls.

See Criterion for a Haskell benchmarking library that applies many of the same statistical techniques.

Todo

Serial correlation detection. Multimodal distribution detection. Use kernel density estimators?

YourKit

YourKit is kindly supporting open source projects with its full-featured Java Profiler.

YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products:

License

Licensed under EPL

criterium's People

Contributors

alexander-yakushev avatar bronsa avatar chrisblom avatar danielcompton avatar davidsantiago avatar dm3 avatar drewr avatar hugoduncan avatar jafingerhut avatar marcuswr avatar o-i avatar orend avatar stig avatar yzernik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.