-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmbench.hs
62 lines (56 loc) · 1.71 KB
/
bmbench.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-***********************************************************************
* BM Bench - bmbench.hs (Haskell)
* (c) Marco Vieth, 2005
* http://www.benchmarko.de
*
* 14.04.2005 0.01 first tests
*
*
* Usage:
* ghc -O3 -fasm bmbench.hs -o bmbench.ghc_run
* bmbench([bench1], [bench2], [n]) ...
*
*
***********************************************************************-}
import System(getArgs, getProgName, exitWith, ExitCode(..))
square :: Int -> Int
square n = n * n
--
-- bench01 (Integer 16/32 bit)
-- (sum of 1..n) mod 65536
-- (Javascript seems to have no Integer arithmetic, so same as bench02...)
{-
function bench01(loops, n) {
var x = 0;
var sum1 = myint(((n / 2) * (n + 1)) % 65536); -- assuming n even! (sum should be ...)
// do not use '& 0xffff' since this converts sum1 to 0 for stand alonw engine
while (loops-- > 0) {
for (var i = n; i > 0; i--) {
x += i;
}
if (loops > 0) { // some more loops left?
x %= 65536; // (do not use &= 0xffff)
x -= sum1; // yes, set x back to 0
if (x != 0) { // now x must be 0 again
x++; // force error for many wrong computations
break; // Error //alert("Error(bench01): x="+ x);
}
}
}
//if (isInt(x)) { System.stdout.writeln("Yes, it is integer!"); }
return x % 65536;
}
-}
main = do
arg <- getArgs
case arg of
[number] -> putStrLn (show (square (read number)))
_ -> do
progname <- getProgName
putStrLn ("Usage: " ++ progname ++ " number")
exitWith (ExitFailure 1)
{-
//
// BM Bench - bmbench.js (JavaScript)
// ...
-}