"Fossies" - the Fresh Open Source Software Archive

Member "heaplayers-351/benchmarks/mudlle/test.mud" (15 Oct 2003, 1912 Bytes) of package /linux/misc/old/heaplayers_3_5_1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 rfact2 = fn (x) if (x > 1) x * rfact2(x - 1) else 1;
    2 rfact = fn (int x) if (x > 1) x * rfact(x - 1) else 1;
    3 ifact = fn (int x)
    4   [
    5     | r |
    6     r = 1;
    7     while (x > 1)
    8       [
    9 	r = r * x;
   10 	x = x - 1;
   11       ];
   12     r
   13   ];
   14 
   15 test = fn (f, x, n)
   16   [
   17     | s |
   18 
   19     s = ctime();
   20     while ((n = n - 1) >= 0) f(x);
   21     ctime() - s
   22   ];
   23 
   24 /*
   25 Times (A2500/30, 25mhz 68030):
   26 heap: 1.2M
   27 
   28 unoptimised interpreted ifact(10000): 39200
   29 unoptimised interpreted rfact(10000): 55200
   30 compiled ifact(10000): 1360
   31 compiled rfact(10000): 3160
   32 compiled inferred ifact(10000): 1040
   33 compiled inferred rfact(10000): 2800
   34 compiled inferred+decl rfact(10000): 2060
   35 compiled inferred+decl ifact(10000): 980
   36 
   37 */
   38 
   39 ll = list(1, 6, 7, 9, 12, 8, 999, -1);
   40 
   41 test1 = fn (x) lmap(fn (a) a + 1, ll);
   42 test2 = fn (x) lforeach(fn (a) a + 1, ll);
   43 test3 = fn (x) mlmap(fn (a) a + 1, ll);
   44 test4 = fn (x) mlforeach(fn (a) a + 1, ll);
   45 test5 = fn (x) lexists?(fn (a) a > 10, ll);
   46 test6 = fn (x) mlexists?(fn (a) a > 10, ll);
   47 test7 = fn (x) memq(x, ll);
   48 test8 = fn (x) mmemq(x, ll);
   49 
   50 
   51 /* Sparc: 2.1M heap
   52 test(ifact, 12, 1000000): 7.5s
   53 test(rfact, 12, 100000): 4.3s
   54 
   55 inferred: ifact: 6.8s
   56 	  rfact: 4.0s
   57 
   58 100000 iterations:
   59 test1: 4.0s
   60 test2: 2.0s
   61 test3: 1.8s
   62 test4: 0.7s
   63 */
   64 
   65 mlmap = fn (f, l)
   66 if (l == null) null
   67 else
   68 [
   69   | first, last |
   70 
   71   last = first = f(car(l)) . null;
   72   l = cdr(l);
   73   while (l != null)
   74     [
   75       | new |
   76 
   77       new = f(car(l)) . null;
   78       set_cdr!(last, new);
   79       new = last;
   80       l = cdr(l);
   81     ];
   82   first
   83 ];
   84 
   85 mlforeach = fn (f, l)
   86 while (l != null)
   87 [
   88   f(car(l));
   89   l = cdr(l);
   90 ];
   91 
   92 mlexists? = fn "fn l -> x. Returns first element x of l for which fn(x) is true, false if none found" (f, l)
   93   loop
   94     [
   95       | x |
   96 
   97       if (l == null) exit false
   98       else if (f(x = car(l))) exit x
   99       else l = cdr(l);
  100     ];
  101 
  102 mmemq = fn (x, l)
  103   loop
  104     if (l == null) exit false
  105     else if (x == car(l)) exit l
  106     else l = cdr(l);