aboutsummaryrefslogtreecommitdiff
path: root/comparison/SML
diff options
context:
space:
mode:
Diffstat (limited to 'comparison/SML')
-rw-r--r--comparison/SML/Makefile2
-rw-r--r--comparison/SML/bsort-20000.sml42
-rw-r--r--comparison/SML/isort-20000.sml35
3 files changed, 78 insertions, 1 deletions
diff --git a/comparison/SML/Makefile b/comparison/SML/Makefile
index 0e4e2e3..14dca02 100644
--- a/comparison/SML/Makefile
+++ b/comparison/SML/Makefile
@@ -1,5 +1,5 @@
COMMAND = sml
-TARGET = dummy.sml ack3-11.sml fib38.sml bsort-40000.sml isort-40000.sml qsort-260000.sml msort-260000.sml
+TARGET = dummy.sml ack3-11.sml fib38.sml bsort-20000.sml isort-20000.sml qsort-260000.sml msort-260000.sml
BENCHMARK = bash ../tools/sptest_scripts.sh
LOG = log.txt
diff --git a/comparison/SML/bsort-20000.sml b/comparison/SML/bsort-20000.sml
new file mode 100644
index 0000000..2129cd6
--- /dev/null
+++ b/comparison/SML/bsort-20000.sml
@@ -0,0 +1,42 @@
+(*
+https://gist.github.com/masquerade0324/68f4f3fd3ab897fbe1ad
+*)
+
+fun bs xs 0 = xs
+ | bs (x::y::ys) n =
+ if (x<y) then x::(bs (y::ys) (n-1))
+ else y::(bs (x::ys) (n-1))
+ | bs xs _ = xs;
+
+fun go xs 0 = xs
+ | go xs n = go (bs xs n) (n-1);
+
+
+fun bsort [] = []
+ | bsort xs = go xs (length(xs) - 1);
+
+
+(* Creates a random list *)
+local
+ val nextInt = Random.randRange(1,10000);
+ val r = Random.rand(1,1);
+in
+ fun mkRandList 0 = []
+ | mkRandList n = (nextInt r)::(mkRandList (n-1))
+end;
+
+
+(* Validation checks *)
+fun validation [] = true
+ | validation (x::xs) =
+ let fun validation_cons x [] = true
+ | validation_cons x (y::ys) =
+ if x<=y then validation_cons y ys
+ else false
+ in
+ validation_cons x xs
+ end;
+
+
+(* Main *)
+validation(bsort(mkRandList 20000));
diff --git a/comparison/SML/isort-20000.sml b/comparison/SML/isort-20000.sml
new file mode 100644
index 0000000..d3648cc
--- /dev/null
+++ b/comparison/SML/isort-20000.sml
@@ -0,0 +1,35 @@
+(* http://www.codecodex.com/wiki/Insertion_sort#Standard_ML *)
+fun insertsort [] = []
+ | insertsort (x::xs) =
+ let fun insert (x, []) = [x]
+ | insert (x, y::ys) =
+ if x<=y then x::y::ys
+ else y::insert(x, ys)
+ in insert(x, insertsort xs)
+ end;
+
+
+(* Creates a random list *)
+local
+ val nextInt = Random.randRange(1,10000);
+ val r = Random.rand(1,1);
+in
+ fun mkRandList 0 = []
+ | mkRandList n = (nextInt r)::(mkRandList (n-1))
+end;
+
+
+(* Validation checks *)
+fun validation [] = true
+ | validation (x::xs) =
+ let fun validation_cons x [] = true
+ | validation_cons x (y::ys) =
+ if x<=y then validation_cons y ys
+ else false
+ in
+ validation_cons x xs
+ end;
+
+
+(* Main *)
+validation(insertsort(mkRandList 20000));