Skip to content

Instantly share code, notes, and snippets.

@kjagiello
Last active December 12, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjagiello/4734986 to your computer and use it in GitHub Desktop.
Save kjagiello/4734986 to your computer and use it in GitHub Desktop.
fun measureTime f =
let
val t = Timer.startRealTimer ()
in
(f (), Timer.checkRealTimer t)
end
fun readAll (h, acc) =
let
val s = TextIO.inputLine h
in
case s
of SOME (s) => readAll (h, acc ^ s)
| NONE => acc
end
fun testFile n =
let
val f = TextIO.openIn n
val s = readAll (f, "")
val (cr, ct) = measureTime (fn () => compress(explode s))
val (dr, dt) = measureTime (fn () => implode(decompress cr))
val r =
case (s = dr)
of true => "SUCCEEDED"
| false => "FAILED"
in
("Test " ^ r ^ " in:", ct + dt, "seconds (compress:", ct, "s, decompress:", dt, "s)")
end
;
@kjagiello
Copy link
Author

Generating a file with 1000 random ASCII characters: tr -cd '[:alnum:]' < /dev/urandom | fold -w1000 | head -n1 > 1000.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment