Collection of benchmarks of functional programming languages and proof assistants.

Overview

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. The main goal of this repository is to track Kind2's performance compared to alternatives.

Type Checker

The tests below measure type-checking and theorem proving performance.

nat_exp

Proof that is-even (2 ^ N) == true. Measures type-level evaluation speed.

add (a: Nat) (b: Nat) : Nat
add x zero     = x
add x (succ y) = succ (add x y)

mul (a: Nat) (b: Nat) : Nat
mul a zero     = zero
mul a (succ b) = add a (mul a b)

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

Main : Equal (is_even (exp N2 N)) true
Main = refl

Comments: Kind2 is many times faster than alternatives, due to HVM's raw speed.

tree_fold

Proof that (tree-fold (full-tree N) and true) == true. Measures type-level evaluation speed.

full_tree (d: Nat) : Tree
full_tree zero     = leaf
full_tree (succ d) = let branch = full_tree d; node branch branch

tree_fold (a: Tree) (p: Type) (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 (a: 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

Comments: Kind2 is many times faster than alternatives, due to HVM's raw speed.

nat_exp_church

Proof that is-even (2 ^ N) == true, Church encoded. Measures type-level evaluation asymptotics.

Church.add (a: Church.Nat) (b: Church.Nat) : Church.Nat
Church.add a b = p => f => z => a p f (b p f z)

Church.mul (a: Church.Nat) (b: Church.Nat) : Church.Nat
Church.mul a b = p => f => a p (b p f)

Church.exp (a: Church.Nat) (b: Church.Nat) : Church.Nat
Church.exp a b = p => b (p -> p) (a p)

Main : Equal (Church.is_even (Church.exp Church.N2 N)) Church.true
Main = refl

Comments: Kind2 is exponentially faster than alternatives, due to HVM's optimal reduction.

tree_fold_church

Proof that (tree-fold (full-tree N) and true) == true, Church encoded. Measures type-level evaluation asymptotics.

Church.full_tree (d: Church.Nat) : Church.Tree
Church.full_tree d = p => n => l => d p (t => n t t) l

Church.tree_fold (a: Church.Tree) (p: Type) (n: p -> p -> p) (l: p) : p
Church.tree_fold t p n l = t p n l

Church.force_tree (a: Church.Tree) : Church.Bool
Church.force_tree t = Church.tree_fold t Church.Bool (a => b => Church.and a b) Church.true

Main : Equal (Church.force_tree (Church.full_tree N)) Church.true
Main = refl

Comments: Kind2 is exponentially faster than alternatives, due to HVM's optimal reduction.

vector

Type-checks a huge vector with several meta variables. Measures parser and elaborator performance.

TODO

STLC

Type-checks a simply typed λ-calculus interpreter. Measures parser and elaborator performance.

TODO

RLP

Type-checks a RLP identity proof. Measures performance of heavy-weight equational reasoning.

TODO

Runtime

The tests below measure runtime performance.

list_fold

Creates a large list and folds over it with uint64 addition. Measures runtime evaluation speed for sequential recursion.

Fold <t: Type> (list: List t) <p: Type> (cons: t -> p -> p) (nil: p) : p
Fold t Nil         p c n = n
Fold t (Cons x xs) p c n = c x (Fold xs c n)

Range (n: U60) (list: List U60) : List U60
Range 0 xs = xs
Range n xs = let m = (- n 1); Range m (Cons m xs)

Comments: Kind2 and Haskell have similar performance on sequential recursive algorithms.

tree_fold

Creates a large list and folds over it with uint64 addition. Measures runtime evaluation speed for parallel recursion.

Gen (n: U60) : Tree
Gen 0 = Leaf 1
Gen n = Node (Gen (- n 1)) (Gen (- n 1))

Sum (tree: Tree) : U60
Sum (Leaf x)   = x
Sum (Node a b) = (+ (Sum a) (Sum b))

Comments: Kind2 outperforms Haskell on parallel recursive algorithms.

quicksort

Creates a large list of uint64's and sorts it. Measures runtime evaluation speed for parallel recursion.

TODO

Note: benchmark already available on HVM's repo. Will be ported to Kind2 soon.

composition

Composes a function an exponential amount of times. Measures runtime asymptotics.

TODO

Note: benchmark already available on HVM's repo. Will be ported to Kind2 soon.

lambda_arithmetic

Performs arithmetic with λ-encoded ints. Measures runtime asymptotics.

TODO

Note: benchmark already available on HVM's repo. Will be ported to Kind2 soon.

Replicating

To replicate these benchmarks, just run:

node run benchmark.js

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

Notes

The original sources are available on Checker and Runtime. We attempt to make the test cases as identical as possible. These tests are focused in comparing pure functional programming workloads, which mostly consist of datatype allocation, pattern-matching, functions, closures and recursion. As such, it doesn't cover low-level algorithms that are heavy on mutable array manipulation and in-place loops with mostly numeric workloads.

These benchmarks are focused on runtime and type-level evaluation performance. They do not cover elaboration (yet), which is commonly a significant source of slowdown. Kind2 doesn't have a complex elaborator, thus, it doesn't suffer from this problem; but, in turn, it is slightly more verbose than alternatives in certain areas. For a brilliantly designed elaborator, check smalltt by András Kovács. Kind2 aims to, in a future, incorporate insights from this work. Also, Kind2 does not have a totality checker (yet), so, it is arguably doing less than alternatives; although the cost of the totality checker should be negligible in comparison to general evaluation, but it is still worth noting.

Finally, these the type-checker all use Kind2's Rust interpreter. In theory, Kind2 could be compiled to machine code, which would make it 3-4 faster, but the cost of C compilation would overshadow that. In a future, once we implement incremental compilation, we might be able to pre-compile the type-checker, allowing only user-defined functions to be injected. That would immediately make Kind2's numbers 3-4x lower. There are other incoming optimizations on the making, including a complete GPU runtime!

You might also like...

When a person that doesn't know how to create a programming language tries to create a programming language

When a person that doesn't know how to create a programming language tries to create a programming language

Kochanowski Online Spróbuj Kochanowskiego bez konfiguracji projektu! https://mmusielik.xyz/projects/kochanowski Instalacja Stwórz nowy projekt przez n

Dec 4, 2022

Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

CookBook - Hacktoberfest Find the book you want to read next! PRESENTED BY What is CookBook? A cookbook in the programming context is collection of ti

Nov 17, 2022

Been interested, studying, and developing blockchain security with a Zero Knowledge Proof (ZKP) and create a prototype on the current issue with Philippine's upcoming election. 📥

Been interested, studying, and developing blockchain security with a Zero Knowledge Proof (ZKP) and create a prototype on the current issue with Philippine's upcoming election. 📥

Implementation of Zero Knowledge Proofs in Cryptographic Voting 😎 Reference: Cryptographic Voting – A Gentle Introduction Overview 👨🏻‍💻 The main i

Apr 11, 2022

Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier 🧐 To design and develop a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential ident

Dec 17, 2022

A Web UI toolkit for creating rapid prototypes, experiments and proof of concept projects.

MinimalComps2 A Web UI tookkit for creating rapid prototypes, experiments and proof of concept projects. The site: https://www.minimalcomps2.com/ Full

Apr 18, 2022

NFT vending machine proof of concept built on Solana Pay, Metaplex, Phantom Mobile and Next.js.

Solana NFT Vending Machine This is a proof of concept of an NFT vending machine built using Solana Pay, Metaplex, Phantom Mobile, and Next.js. This wa

Dec 15, 2022

Second-challinge - Frontend Mentor - Social proof section

Second-challinge - Frontend Mentor - Social proof section

Frontend Mentor - Social proof section Welcome! 👋 Thanks for checking out this

Feb 8, 2022

Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Zero Knowledge Private Voting V1 Motivation On-chain governance today is fully transparent at the cost of privacy. This means that every proposal and

Dec 16, 2022

Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Zero Knowledge Private Voting V1 Motivation On-chain governance today is fully transparent at the cost of privacy. This means that every proposal and

Jun 7, 2022
Owner
null
Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks)

eleventy-plugin-directory-output Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks). Sample output from eleven

Eleventy 16 Oct 27, 2022
microregex is an open source and highly curated catalog of regular expression patterns. It offers programmers RegEx snippets that can be quickly exported into a variety of programming languages and distributed around teams.

microregex - A catalog of RegEx patterns View Demo · Report Bug · Request Feature Loved the tool? Please consider contributing ✍️ to help it improve!

Sunit Shirke 4 Oct 25, 2022
JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

Rajkumar Dusad 36 Jan 5, 2023
This is a boilerplate for creating your own languages for various use cases. You can even create your own programming language from scratch!

Bootstrap compiler This is a bootstrap compiler that can be used to compile to compiler written in the target language. You can write a compiler in th

Kaan 3 Nov 14, 2022
A web component that allows you to run high level programming languages on your websites (static websites included!)

Code-Runner-Web-Component A web component that allows you to run high level programming languages on your website via the public Piston API Show your

Marketing Pipeline 28 Dec 16, 2022
Jargon from the functional programming world in simple terms!

Functional Programming Jargon Functional programming (FP) provides many advantages, and its popularity has been increasing as a result. However, each

hemanth.hm 18.1k Jan 4, 2023
Fun λ functional programming in JS

fp-js JavaScript Functional Programming Motivation This purposed for learning functional programming (just that). Features Auto-Curry Option Tooling s

RiN 6 Feb 4, 2022
Functional Programming with NestJS, Prisma. immutable, pure, stateless

Functional-NestJS Functional Programming with NestJS, Prisma. immutable, pure, stateless. 1. Introduction A production ready typescript backend reposi

y0on2q 40 Dec 6, 2022
Typescript library for functional programming.

Sa Lambda Typescript library for functional programming. Document TODO Either Maybe Iterator Pipe & Flow Task (Promise-Like) some math utils Installat

SoraLib 9 Dec 6, 2022
A RabbitMQ client for TypeScript, with functional programming in mind.

RabbitMQ-fp Lets feed our Rabbit' nicely ?? This repository contains a wrapper over amqplib written in Typescript with an accent of functionnal progra

MansaGroup 3 Sep 6, 2022