fun cross_map f xs ys = List.concat (List.map (fn x => map (f x) ys) xs) fun tails xs = xs :: (if null xs then [] else tails (tl xs)) fun init (x :: (ys as (_ :: _))) = x :: init ys | init _ = [] fun inits xs = xs :: (if null xs then [] else inits (init xs)) fun list_sum xs = let fun aux (x1::x2::x3::x4::xs) a = aux xs (a+x1+x2+x3+x4) | aux (x1::x2::xs) a = aux xs (a+x1+x2) | aux (x1::xs) a = aux xs (a+x1) | aux [] a = a in aux xs 0 end (* The following two functions show raums beating lists handily. Now we want to try the other thing. fun run_raum_tests () = let open Raum val k1 = tabulate(300, fn i => i) val t1 = tails k1 val r1 = cross_map (fn x => fn y => rev (rev x @ rev y)) t1 t1 in List.map length r1 end fun run_list_tests () = let open List val k1 = tabulate(300, fn i => i) val t1 = tails k1 val r1 = cross_map (fn x => fn y => rev (rev x @ rev y)) t1 t1 in List.map length r1 end *) fun run_raum_tests () = let open Raum val k1 = tabulate(2000, fn i => i) val t1 = inits k1 val m1 = List.map tails t1 in List.map (List.map sum) m1 end fun run_list_tests() = let open List val k1 = tabulate(2000, fn i => i) val t1 = inits k1 val m1 = List.map tails t1 in List.map (List.map list_sum) m1 end fun timer f = let val tt = Timer.startCPUTimer() val _ = f () val {usr = u, sys = s} = Timer.checkCPUTimer tt in Time.+(u, s) (* print (Time.toString (Time.+(u, s))) *) end (* SML/NJ: - timer run_list_tests; {sys=TIME {usec=12634294}, usr=TIME {usec=63714103}} - timer run_raum_tests; {sys=TIME {usec=27963}, usr=TIME {usec=410971}} For size 300, raums were 174 × faster than lists. For the (List.map tails (inits (tabulate ...))) test case, - timer run_list_tests TIME {usec=16016151} - timer run_raum_tests; TIME {usec=31587986} raums were 2 × slower than lists. Mlton: % raum-all -l 5.085 % raum-all -r 0.246 For size 300, raums were 21 × faster than lists. One factor here is that the list functions are much smaller than the raum ones so are more likely to be inlined. % ctime raum-all @MLton fixed-heap 2G -- -l Out of memory. Unable to allocate heap with 1,196,589,064 bytes. 734.740 user + 9.190 system = 743.930 total seconds. % ctime raum-all @MLton fixed-heap 2G -- -r 7.240 user + 0.120 system = 7.360 total seconds. (7.6 total seconds with the default heap size.) That's 744 seconds and crash for lists compared with 7.6 for raums. So raums are at least 98 × faster than lists for this test, where the size was 1000. For the (List.map tails (inits (tabulate ...))) test case, raums were 1.3 × FASTER than lists (where they had been 12.4 times slower for SML/NJ). The rest was revised. % ctime raum-all -l 17.083 % ctime raum-all -r 14.670 or raums being 1.16 × faster than lists. *)