diff options
Diffstat (limited to 'comparison/OCaml')
| -rw-r--r-- | comparison/OCaml/Makefile | 6 | ||||
| -rw-r--r-- | comparison/OCaml/bsort20000.ml | 39 | ||||
| -rw-r--r-- | comparison/OCaml/isort20000.ml | 36 |
3 files changed, 78 insertions, 3 deletions
diff --git a/comparison/OCaml/Makefile b/comparison/OCaml/Makefile index d300b15..9db7726 100644 --- a/comparison/OCaml/Makefile +++ b/comparison/OCaml/Makefile @@ -1,7 +1,7 @@ CC = ocamlopt CFLAGS = BENCHMARK = bash ../tools/sptest_commands.sh -TARGET = ack3_11 fib38 bsort40000 isort40000 qsort260000 msort260000 +TARGET = ack3_11 fib38 bsort20000 isort20000 qsort260000 msort260000 LOG = log.txt @@ -18,10 +18,10 @@ ack3_11: ack3_11.ml fib38: fib38.ml $(CC) $(CFLAGS) $< -o $@ -bsort40000: bsort40000.ml +bsort20000: bsort20000.ml $(CC) $(CFLAGS) $< -o $@ -isort40000: isort40000.ml +isort20000: isort20000.ml $(CC) $(CFLAGS) $< -o $@ qsort260000: qsort260000.ml diff --git a/comparison/OCaml/bsort20000.ml b/comparison/OCaml/bsort20000.ml new file mode 100644 index 0000000..29a369c --- /dev/null +++ b/comparison/OCaml/bsort20000.ml @@ -0,0 +1,39 @@ +open Format + +let rec bs (alist : int list) n = + match alist with + (x::y::ys) -> + if x<y then x::(bs (y::ys) (n-1)) + else y::(bs (x::ys) (n-1)) + | xs -> xs;; + + +let rec go xs n = + match n with + 0 -> xs + | n -> go (bs xs n) (n-1);; + +let bsort alist = + match alist with + [] -> [] + | xs -> go xs (List.length(xs) - 1);; + + +let rec mkRandList n = + match n with + 0 -> [] + | n -> (Random.int 10000)::(mkRandList (n-1));; + + +let rec validation alist = + let rec validation_cons x blist = + match blist with + [] -> true + | y::ys -> if x<=y then (validation_cons y ys) else false + in + match alist with + [] -> true + | x::xs -> validation_cons x xs;; + + +let () = print_bool (validation (bsort (mkRandList 20000)));; diff --git a/comparison/OCaml/isort20000.ml b/comparison/OCaml/isort20000.ml new file mode 100644 index 0000000..ddcdd2a --- /dev/null +++ b/comparison/OCaml/isort20000.ml @@ -0,0 +1,36 @@ +open Format + +let rec insert x ylist = + match ylist with + [] -> [x] + | y::ys -> if x<=y + then x::y::ys + else y::(insert x ys);; + + +let rec isort (alist : int list) = + match alist with + [] -> [] + | x::xs -> insert x (isort xs);; + + + +let rec mkRandList n = + match n with + 0 -> [] + | n -> (Random.int 10000)::(mkRandList (n-1));; + + +let rec validation alist = + let rec validation_cons x blist = + match blist with + [] -> true + | y::ys -> if x<=y then (validation_cons y ys) else false + in + match alist with + [] -> true + | x::xs -> validation_cons x xs;; + + +let () = print_bool (validation (isort (mkRandList 20000)));; + |
