From fc50417e4317334f5ae2d396cb6d517b8e276947 Mon Sep 17 00:00:00 2001 From: John Benediktsson <mrjbq7@gmail.com> Date: Tue, 24 Apr 2012 17:29:26 -0700 Subject: [PATCH] benchmark.combinatorics: adding a combinatorics benchmark. --- .../combinatorics/combinatorics.factor | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 extra/benchmark/combinatorics/combinatorics.factor diff --git a/extra/benchmark/combinatorics/combinatorics.factor b/extra/benchmark/combinatorics/combinatorics.factor new file mode 100644 index 0000000000..ce7c26bddc --- /dev/null +++ b/extra/benchmark/combinatorics/combinatorics.factor @@ -0,0 +1,30 @@ +! Copyright (C) 2012 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: combinators kernel math math.combinatorics math.ranges +sequences ; + +IN: benchmark.combinatorics + +: bench-combinations ( n -- ) + [1,b] dup clone [ + { + [ all-combinations drop ] + [ [ drop ] each-combination ] + [ [ first 2 = ] find-combination drop ] + [ 0 [ sum + ] reduce-combinations drop ] + } 2cleave + ] with each ; + +: bench-permutations ( n -- ) + iota { + [ all-permutations drop ] + [ [ drop ] each-permutation ] + [ [ first 2 = ] find-permutation drop ] + [ 0 [ sum + ] reduce-permutations drop ] + } cleave ; + +: combinatorics-benchmark ( -- ) + 15 bench-combinations 8 bench-permutations ; + +MAIN: combinatorics-benchmark