Skip to content

Commit

Permalink
more bench
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Oct 11, 2024
1 parent b913cd7 commit 2632c9f
Show file tree
Hide file tree
Showing 3 changed files with 753 additions and 0 deletions.
93 changes: 93 additions & 0 deletions wasm/test/fannkuch2.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(* The Computer Language Benchmarks Game
http://shootout.alioth.debian.org/
contributed by Isaac Gouy, transliterated from Mike Pall's Lua program
*)

let fannkuch n =
let p = Array.make n 0 in
let q = Array.make n 0 in
let s = Array.make n 0 in
let sign = ref 1 in
let maxflips = ref 0 in
let sum = ref 0 in
for i = 0 to n - 1 do
p.(i) <- i;
q.(i) <- i;
s.(i) <- i
done;
while true do
let q0 = ref p.(0) in
if !q0 <> 0
then (
for i = 1 to n - 1 do
q.(i) <- p.(i)
done;
let flips = ref 1 in
while
let qq = q.(!q0) in
if qq = 0
then (
sum := !sum + (!sign * !flips);
if !flips > !maxflips then maxflips := !flips;
false)
else true
do
let qq = q.(!q0) in
q.(!q0) <- !q0;
(if !q0 >= 3
then
let i = ref 1 in
let j = ref (!q0 - 1) in
while
let t = q.(!i) in
q.(!i) <- q.(!j);
q.(!j) <- t;
incr i;
decr j;
!i < !j
do
()
done);
q0 := qq;
incr flips
done);
if !sign = 1
then (
let t = p.(1) in
p.(1) <- p.(0);
p.(0) <- t;
sign := -1)
else
let t = p.(1) in
p.(1) <- p.(2);
p.(2) <- t;
sign := 1;
try
for i = 2 to n - 1 do
let sx = s.(i) in
if sx <> 0
then (
s.(i) <- sx - 1;
raise Exit);
if i = n - 1
then (
if false then Format.eprintf "%d %d@." !sum !maxflips;
exit 0);
s.(i) <- i;
let t = p.(0) in
for j = 0 to i do
p.(j) <- p.(j + 1)
done;
p.(i + 1) <- t
done
with Exit -> ()
done

let n = 10

let pf = fannkuch n

(*
//print(pf[0] + "\n" + "Pfannkuchen(" + n + ") = " + pf[1]);
*)
Loading

0 comments on commit 2632c9f

Please sign in to comment.