Giter Club home page Giter Club logo

functional-benchmarks's Introduction

Functional Benchmarks

This repository contains a collection of benchmarks of functional programming languages and proof assistants. It is split in two categories, Checker and Runtime, which measure the time it takes to type-check, and run, a program, respectivelly.

Checker.nat_exp

Performs exponentiation of natural numbers on the type-level.

exp : Nat -> Nat -> Nat
exp a zero     = succ zero
exp a (succ b) = mul a (exp a b)

main : Equal (is-even (exp C-2 N)) true
main = refl

Checker.nat_exp_church

Performs exponentiation of Church encoded natural numbers on the type-level.

C-exp : C-Nat -> C-Nat -> C-Nat
C-exp a b =  p -> b (p -> p) (a p)

main : Equal (C-is-even (C-exp C-2 N)) C-true
main = refl

Checker.tree_fold

Creates a perfect binary tree and folds over it with Boolean conjunction on the type level.

tree-fold : Tree -> (p : Set) -> (n : p -> p -> p) -> (l : p) -> p
tree-fold leaf       p n l = l
tree-fold (node a b) p n l = n (tree-fold a p n l) (tree-fold b p n l)

force-tree : Tree -> Bool
force-tree t = tree-fold t Bool ( a b -> and a b) true

main : Equal (force-tree (full-tree N)) true
main = refl

Checker.tree_fold_church

Creates a Church encoded perfect binary tree and folds over it with Boolean conjunction on the type level.

C-tree-fold : C-Tree -> (p : Set) (n : p -> p -> p) (l : p) -> p
C-tree-fold t p n l = t p n l

C-force-tree : C-Tree -> C-Bool
C-force-tree t = C-tree-fold t C-Bool ( a b -> C-and a b) C-true

Main : Equal (C-force-tree (C-full-tree N)) C-true
Main = Base.refl

Runtime.list_fold

Creates a large list and folds over it with uint64 addition.

fold :: List a -> (a -> r -> r) -> r -> r
fold Nil         c n = n
fold (Cons x xs) c n = c x (fold xs c n)

range :: Word64 -> List Word64 -> List Word64
range 0 xs = xs
range n xs =
  let m = n - 1
  in range m (Cons m xs)

main = print $ fold (range N Nil) (+) 0

Runtime.tree_fold

Creates a large list and folds over it with uint64 addition.

gen :: Word32 -> Tree
gen 0 = Leaf 1
gen n = Node (gen(n - 1)) (gen(n - 1))

sum :: Tree -> Word32
sum (Leaf x)   = 1
sum (Node a b) = sun a + sun b

main = sum (gen N)

Replicating

To replicate these benchmarks, just run:

node run benchmark.js

For specific commands, check the contents of benchmark.js.

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.