Git Product home page Git Product logo

chronograph's Introduction

Build Status

Chronograph

An instrumentation wrapper for Haskell data

Chronograph allows you to measure and record data and IO evaluation time.

Chronograph is meant to be used as a lightweight, unobtrusive mechanism to collect timings of evaluations and IO actions during program execution.

Installation

Install the latest version from Hackage:

$ cabal install chronograph

Alternatively, git clone this repo and:

$ cabal install

Use

To measure the evaluation time of an expression, pass it as an argument to the 'chrono' function:

> import Data.Chronograph
>
> let timed_someExpr = chrono (someExpr)

'chrono' has the type 'a -> Chronograph a'

Then just use the 'val' of a 'Chronograph' everywhere you would use the original expression.

> doSomethingWith (val timed_someExpr)

You can check the evaluation time with 'measure'

> let exprTime = measure timed_someExpr

For IO actions, use 'chronoIO'.

Here's a full example, demonstrating both pure and IO functions:

> import Control.Applicative
> import System.Environment
> import Data.Chronograph
>
> import Text.Printf
>
> procFile :: FilePath -> IO ()
> procFile fp = do
>     doc <- readFile fp
>     let wc = length $ lines doc
>     void $ chronoPrint "time to calc length" (chrono wc)
>
> procIO :: FilePath -> IO ()
> procIO fp = do
>     wc <- chronoIO $ fileLinesIO fp
>     void $ chronoPrint "" wc
>
> fileLinesIO :: FilePath -> IO Int
> fileLinesIO fp = length . lines <$> readFile fp
>
> main :: IO ()
> main = do
>     args <- getArgs
>     putStrLn "pure Chronograph"
>     mapM_ procFile args
>     putStrLn "IO Chronograph"
>     mapM_ procIO args

Evaluation Order

Values in a Chronograph are lazy, and won't be evaluated until either the 'val' or 'measure' is evaluated.

'chronoBy' and 'chronoIOBy' take an evaluation parameter to control how much of the data will be evaluated and timed. The shortcut functions 'chrono' and 'chronoNF' are provided for the common cases of weak head normal form (seq) and normal form (deepseq).

Join in

File bugs in the GitHub issue tracker.

Master git repository:

  • git clone https://github.com/JohnLato/chronograph

License

BSD3. See LICENSE for terms of copyright and redistribution.

chronograph's People

Contributors

johnlato avatar pacak avatar

Watchers

 avatar  avatar  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.