Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ocaml versus Scheme

443 views
Skip to first unread message

phi5...@yahoo.ca

unread,
Dec 7, 2008, 7:02:16 PM12/7/08
to
As I told before, I use Scheme and Clean to do my homework. Usually,
the TAs require fast and small executables (less than 1.5M). If one
wants a good grade, his/her programs must not be much slower than the
corresponding C code. Bigloo pretty fast, even when compared to gcc.
However, I decided to give OCAML a try for two reasons:

1 --- Quite a few people say that it is considerably faster than
Bigloo.

2 --- It has a nice notation for arithmetics, closer to the
tranditional one than Bigloo.

In general, a homework is a small program (200 to 300 lines), that one
needs to apply to huge amount of data, like inverting gigantic arrays.
Bigloo takes about 5 minutes to solve a linear system with 5000 unknow
values. Ocaml with its normal arrays takes twice as much. However, the
normal arrays are limited to 2000000 elements. Bigarrays turned out to
be 20 times slower than Bigloo. Of course, this was my first program
in OCAML, and I guess I made many unforgivable blunders. I know that
there are many people here that program well in OCAML. Could you tell
me what I did wrong?

open Bigarray;;

let solvit mm =
let r= Array2.dim1 mm in
let c= r+1 in
let rat = ref 0.0 and tx= ref 0.0 in
for k=0 to r-2 do
for i=k+1 to r-1 do
rat := (Array2.get mm i k) /. (Array2.get mm k k);
for j=k to c-1 do
Array2.set mm i j ((Array2.get mm i j) -. rat.contents *.
(Array2.get mm k j))
done
done
done;
for i= r-1 downto 0 do
tx := 0.0;
for j= i+1 to r-1 do
tx := !tx -. (Array2.get mm i j) *. (Array2.get mm j r)
done;
Array2.set mm i r (((Array2.get mm i r) +. tx.contents) /.
(Array2.get mm i i))
done;;


let mm= Array2.create float64 c_layout 5000 5001 in
let id= Array2.dim1 mm and jd= Array2.dim2 mm and
acc= ref 0.0
in (
for i= 0 to (id - 1) do
acc := 0.0;
for j= 0 to (jd - 2) do
let elt= Random.float 100.0 in
( acc := !acc +. elt;
Array2.set mm i j elt )
done;
Array2.set mm i (jd-1) !acc
done;
solvit mm;

for i= 0 to 10 do
Printf.printf "%f " (Array2.get mm i id)
done;
Printf.printf "\nOcaml Time= %f\n" (Sys.time())
);;

phi5...@yahoo.ca

unread,
Dec 8, 2008, 10:18:34 AM12/8/08
to
I modified the OCAML program to make it closer to the homework
specification, which requires the use of one-dimentional arrays.
However this does not change the result, which is OCAML is between ten
and twenty times slower than Scheme (Bigloo, Stalin or Gambit). BTW,
the Array library is slightly faster than the Bigarray library.
However, it is limited to 2097151 elements. The benchmark starts with
5000 unknowns, which gives 25000000 elements. The array needs to be
one-demensional because the sover will be used to solve partial
differential equations (heat transfer in the ocian); one must
manipulate the indexes to squeeze the array into a band. Anyway, here
is how I compile the OCAML program:

ocamlopt bigarray.cmxa -inline 200 -ccopt -O3 -unsafe matone.ml -o
matone.exe

Here is how I use it:

matone 5000

Here is how I compile the Scheme program:

bigloo -Obench -farithmetic -O3 matb.scm -o matb.exe

Here is how I use the Scheme program:

matb 5000

The Scheme program produces an answer after 2 minutes. The OCAML
program gives the same result after 36 minutes. I will take the
problem to the OCAML list. However I would like to have your opinion
before doing that, since I do not want to present a program with
ridiculous blunders to experts in OCAML. Here is the OCAML program:

open Bigarray;;

let make_system r=
let c= r+1 in
let m= Array1.create float64 c_layout (r * c) in
let xx= ref 0.0 and s= ref 0.0 in
for i= 0 to r-1 do
s := 0.0;
for j=0 to r-1 do
xx := Random.float 100.0;
s := s.contents +. xx.contents;
Array1.set m (i*c+j) xx.contents
done;
Array1.set m (i*c+r) s.contents
done;
m
;;

let iii= ref 0;;

let swapit m c k l=
let t = ref 0.0 in
iii := iii.contents + 1;
for j=0 to c-1 do
t := Array1.get m (k*c+j);
Array1.set m (k*c+j) (Array1.get m (l*c+j));
Array1.set m (l*c+j) t.contents
done
;;

let find_max m c k idx=
let i= ref idx in
for l= k+1 to c-2 do
if (abs_float (Array1.get m (l*c+k))) >
(abs_float (Array1.get m (i.contents * c + k))) then
i := l
done;
if i.contents <> k then swapit m c k i.contents
;;

let solvit mm r c=
let rat = ref 0.0 and tx= ref 0.0 and mkk= ref 0.0 in


for k=0 to r-2 do

find_max mm c k k;
mkk := Array1.get mm (c*k + k);
for i= k+1 to r-1 do
rat := (Array1.get mm (i*c + k)) /. mkk.contents;


for j=k to c-1 do

Array1.set mm (i*c+j) ( (Array1.get mm (i*c+j)) -.
rat.contents *. (Array1.get mm
(k*c + j)))
done
done
done;
for i=r-1 downto 0 do
tx := 0.0;
for j=i+1 to r-1 do
tx := tx.contents -. (Array1.get mm (i*c + j)) *.
(Array1.get mm (j*c + r))
done;
Array1.set mm (i*c+r) ((( Array1.get mm (i*c + r)) +.
tx.contents) /.
(Array1.get mm (i*c + i)))
done
;;


let nels () =
try
int_of_string Sys.argv.(1)
with
_ -> 5000
;;

let r= nels () in
let c= (r+1) in
let mm= make_system r in
(
solvit mm r c;
for i= 0 to (min (r-1) 10) do
Printf.printf "%8.3f " (Array1.get mm (i*c+r))
done;
print_newline();
Printf.printf "Number of swaps= %d\n" iii.contents;


Printf.printf "\nOcaml Time= %f\n" (Sys.time())

);;

Here is the Scheme program:

;; Compile: bigloo -Obench -farithmetic -O3 matb.scm -o matb.exe

(module example
(main main)
(option (set! *genericity* #f))
(extern
(macro printf::int (::string ::double) "printf")
(clock::int () "clock") ))

(define iii 0)

(define-macro ($ v c i j)
`(f64vector-ref ,v (+fx (*fx ,i ,c) ,j) ) )

(define-macro ($! v c i j val)
`(f64vector-set! ,v (+fx (*fx ,i ,c) ,j) ,val))

(define-macro (!= x y)
`(not (=fx ,x ,y)))

(define (prt m r c)
(do ( (i 0 (+fx i 1)) ) ( (>=fx i r) )
(newline)
(do ((j 0 (+fx j 1)) ) ( (>=fx j c) )
(printf " %4.3f " ($ m c i j) ) )))

(define (make-system r)
(let* ( (c (+fx r 1))
(m (make-f64vector (*fx r c) 0.0 ))
(xx 0.0)
(s 0.0) )

(do ( (i 0 (+fx i 1)) ) ( (>=fx i r) m)
(set! s 0.0)
(do ((j 0 (+fx j 1) ) ) ( (>=fx j r) ($! m c i j s) )
(set! xx (fixnum->flonum (random 3873)))
(set! s (+fl s xx))
($! m c i j xx )) ) ))

(define (swapit m c k l)
(let ((t 0.0))
(set! iii (+fx iii 1))
(do ( (j 0 (+fx j 1)) ) ( (>=fx j c) )
(set! t ($ m c k j ) )
($! m c k j ($ m c l j) )
($! m c l j t) ) ) )

(define (find-max m c k i)
(do ( (l (+fx k 1) (+fx l 1)) )
( (>=fx l (-fx c 1)) (when (!= i k) (swapit m c k i )))
(when (>fl (absfl ($ m c l k)) (absfl ($ m c i k)) )
(set! i l) ) ))

(define (solvit m r)
(let ( (c (+fx r 1))
(rat 0.0)
(mkk 0.0))

(do ( (k 0 (+fx k 1)) ) ( (>=fx k (-fx r 1)))
(find-max m c k k)
(set! mkk ($ m c k k) )

(do ( ( i (+fx k 1)(+fx i 1)) ) ( (>=fx i r))
(set! rat (/fl ($ m c i k) mkk ))
(do ( (j k (+fx j 1))) ( (>=fx j c) )
($! m c i j (-fl ($ m c i j)
(*fl rat ($ m c k j ) ) ) )
)
)
)

(do ( (i (-fx r 1) (-fx i 1) ) ) ((<fx i 0) m)
(do ( (j (+fx i 1) (+fx j 1))
(tx 0.0 (-fl tx (*fl ($ m c i j)
($ m c j r )) )) )
( (>=fx j r)
($! m c i r
(/fl (+fl ($ m c i r ) tx)
($ m c i i)) ) ) ))
)
)

(define (elms argv)
(cond ( (<fx (length argv) 2) 2000)
( (string->number (cadr argv)) (string->number (cadr argv)) )
(else 2000)))

(define (main argv)
(let* ( (r (elms argv)) (c (+fx r 1)) (m (solvit (make-system r)
r) ) )
(do ( (i 0 (+fx i 1))) ( (>=fx i (min r 10)) )
(printf " %4.3f " ($ m c i r) ) )
(newline) (display "Bigloo time= ") (display (clock))
(newline) (print "Number of swaps= " iii)) )


klohm...@yahoo.de

unread,
Dec 8, 2008, 11:08:35 AM12/8/08
to

On Dec 8, 3:18 pm, phi50...@yahoo.ca wrote:
> I modified the OCAML program to make it closer to the homework
> specification, which requires the use of one-dimentional arrays.
> However this does not change the result, which is OCAML is between ten
> and twenty times slower than Scheme (Bigloo, Stalin or Gambit). BTW,
> the Array library is slightly faster than the Bigarray library.
> However, it is limited to 2097151 elements. The benchmark starts with
> 5000 unknowns, which gives 25000000 elements. The array needs to be
> one-demensional because the sover will be used to solve partial
> differential equations (heat transfer in the ocian); one must
> manipulate the indexes to squeeze the array into a band. Anyway, here
> is how I compile the OCAML program:

I have never used OCaml myself. However, I am quite surpised that
Bigloo (my favorite Scheme) is much faster than OCaml. Have been
always thinking that one weak point is Bigloo its handling of larger
arrays (memory).

Could you run the Bigloo code without f64 strict type vectors and
check if that will make Bigloo excecution time worse?

I think much better would it be to post your observation on the
fa.caml list. If you study carefully the OCaml source code
distribution you will see that the now lead developer of Bigloo wrote
his PhD under the auspicies of the OCaml team members.

Do you also see the large difference between OCaml and Bigloo when
reducing the size of the arrays? Sometimes larger arrays result in
caching related performance problems.

BUT amigo: I find it strange how you are formatting some of your
Scheme code. What is the reason for this? Why don't you let do your
editor doing the job?

phi5...@yahoo.ca

unread,
Dec 8, 2008, 2:48:40 PM12/8/08
to

The answear to your questions are:

> Do you also see the large difference between OCaml and Bigloo when
> reducing the size of the arrays? Sometimes larger arrays result in
> caching related performance problems.

1 -- If one uses smaller arrays, the difference between OCAML and
Scheme (Stalin, Bigloo or Gambit) drops dramatically. With smaller
arrays, and using the Array library instead of Bigarray, Bigloo is
only two times faster than OCAML. However, for the kind of problem I
am working with (Global warming, and urban heat islands), I need big
arrays.


> Could you run the Bigloo code without f64 strict type vectors and
> check if that will make Bigloo excecution time worse?

2 -- In Bigloo, it is necessary to use the new f64vector to store
uboxed floating point numbers, otherwise the client program will not
be able to access the result. However, I tried to represent 2D arrays
as a vector (normal vector) of f64vectors. The result is that Bigloo
keeps being very fast. The same thing happens to Stalin. In fact, if I
use vector, Bigloo becomes slightly faster, because swaping is
simplified. I will add the code at the end of this article.

> BUT amigo: I find it strange how you are formatting some of your
> Scheme code. What is the reason for this? Why don't you let do your
> editor doing the job?

3 -- As for not letting my editor do the job, the reason is simple: My
editor does not format Scheme. It has keyword coloring, and checks
parenthesis, but that is all. I use Crimson, Texpad, and Scite. Which
editor do you suggest? I need a small editor, since I am supposed to
carry it in my pendrive, and erase it at the end of the class. Could
you suggest me a small editor, that is better than Crimson, or Scite?
In fact, I have been looking for a good editor since long.


By the way, the code below is faster, but since the specification of
the client program needs unboxed vectors, I cannot use it. As you can
see, I store the rows as elements of a normal vector.


;; Compile: bigloo -Obench -farithmetic -O3 matb.scm -o matb.exe

(module example
(main main)
(option (set! *genericity* #f))
(extern
(macro printf::int (::string ::double) "printf")
(clock::int () "clock") ))

(define iii 0)

(define-macro ($ v i j)
`(f64vector-ref (vector-ref ,v ,i) ,j))

(define-macro ($! v i j val)
`(f64vector-set! (vector-ref ,v ,i) ,j ,val))

(define (prt m r c)

(do ( (i 0 (+ i 1)) ) ( (>= i r) )
(newline)
(do ((j 0 (+ j 1)) ) ( (>= j c) )
(printf " %4.3f " ($ m i j) ) )))


(define (make-system r)
(let* ( (c (+ r 1))
(m (make-vector r) )


(xx 0.0)
(s 0.0) )

(do ( (i 0 (+ i 1)) ) ( (>= i r) m)
(vector-set! m i (make-f64vector c) )
(set! s 0.0)
(do ((j 0 (+ j 1) ) ) ( (>= j r) ($! m i j s) )


(set! xx (fixnum->flonum (random 3873)))
(set! s (+fl s xx))

($! m i j xx )) ) ))


(define-macro (!= x y)
`(not (= ,x ,y)))


(define (swapit m k l)
(set! iii (+ iii 1))
(let ((t (vector-ref m k)))
(vector-set! m k (vector-ref m l))
(vector-set! m l t)))

(define (find-max m c k i)
(do ( (l (+fx k 1) (+fx l 1)) )

( (>=fx l (-fx c 1)) (when (!= i k) (swapit m k i )) )
(when (>fl (abs ($ m l k)) (abs ($ m i k)) )


(set! i l) ) ))

(define (solvit m r)
(let ( (c (+fx r 1))
(rat 0.0)
(mkk 0.0))

(do ( (k 0 (+fx k 1)) ) ( (>= k (- r 1)))


(find-max m c k k)

(set! mkk ($ m k k) )
(let ( (mk (vector-ref m k)) )
(do ( ( i (+ k 1)(+ i 1)) ) ( (>= i r))
(set! rat (/fl ($ m i k) mkk ))
(let ((mi (vector-ref m i)))
(do ( (j k (+ j 1))) ( (>= j c) )
(f64vector-set! mi j (-fl (f64vector-ref mi j)
(*fl rat (f64vector-ref mk


j ) ) ) )
)
)
)
)
)

(do ( (i (- r 1) (- i 1) ) ) ((< i 0) m)
(let ( (mi (vector-ref m i)))
(do ( (j (+ i 1) (+ j 1))
(tx 0.0 (-fl tx (*fl (f64vector-ref mi j)
($ m j r )) )) )
( (>= j r)
(f64vector-set! mi r
(/fl (+fl (f64vector-ref mi r ) tx)
(f64vector-ref mi i)) ) ) )
)
)
)
)


(define (main argv)
(let* ( (r 1000) (c 1001) (m (solvit (make-system r) r) ) )
(do ( (i 0 (+ i 1))) ( (>= i 10) )
(printf " %4.3f " ($ m i r) ) )

George Neuner

unread,
Dec 8, 2008, 2:58:38 PM12/8/08
to
On Mon, 8 Dec 2008 08:08:35 -0800 (PST), klohm...@yahoo.de wrote:

>
>On Dec 8, 3:18 pm, phi50...@yahoo.ca wrote:
>> I modified the OCAML program to make it closer to the homework
>> specification, which requires the use of one-dimentional arrays.
>> However this does not change the result, which is OCAML is between ten
>> and twenty times slower than Scheme (Bigloo, Stalin or Gambit). BTW,
>> the Array library is slightly faster than the Bigarray library.
>> However, it is limited to 2097151 elements. The benchmark starts with
>> 5000 unknowns, which gives 25000000 elements. The array needs to be
>> one-demensional because the sover will be used to solve partial
>> differential equations (heat transfer in the ocian); one must
>> manipulate the indexes to squeeze the array into a band. Anyway, here
>> is how I compile the OCAML program:
>
>I have never used OCaml myself. However, I am quite surpised that
>Bigloo (my favorite Scheme) is much faster than OCaml. Have been
>always thinking that one weak point is Bigloo its handling of larger
>arrays (memory).
>
>Could you run the Bigloo code without f64 strict type vectors and
>check if that will make Bigloo excecution time worse?

It probably will be somewhat slower, but not 20x. But Ocaml is
working with typed vectors anyway so the explicitly typed Scheme code
is comparable.

It's likely that the OCaml code is being interpreted rather than
compiled. To the OP: make sure you compile your code with "ocamlopt"
before timing anything.


>I think much better would it be to post your observation on the
>fa.caml list. If you study carefully the OCaml source code
>distribution you will see that the now lead developer of Bigloo wrote
>his PhD under the auspicies of the OCaml team members.
>
>Do you also see the large difference between OCaml and Bigloo when
>reducing the size of the arrays? Sometimes larger arrays result in
>caching related performance problems.

Ocaml has some issues (not problems exactly) with large memory - the
GC copies semi spaces in the nursery, but in the main heap it is a
hybrid mark-sweep/compact that checks utilization to determine whether
to compact (I forget exactly what triggers it). Compactions, if they
occur, can take a lot of time.

George

phi5...@yahoo.ca

unread,
Dec 8, 2008, 9:54:14 PM12/8/08
to
On 8 dez, 17:58, George Neuner <gneun...@comcast.net> wrote:

Hi, George.
In a private emails, OCAML programmers explained me how to improve the
speed of OCAML. Now, it is only 3 times slower than Bigloo. It seems
that I need to explicitly declare the type of arrays, in order to
avoid polymorfism. The modified program is only three times slower
than Scheme. BTW, people who helped me claimed that they were doing so
privately because discussing OCAML in a Scheme list could be
considered OT. However, I know that a lot of people write prototypes
in Scheme, that they converto to other languages after tests.
Therefore I do not think that translating Scheme programs to other
languages is OT. Here is the modified OCAML program (only three times
slower than the Scheme equivalent):

(* ocamlopt bigarray.cmxa -unsafe -ccopt -O3 matone.ml -o matone.exe
*)

open Bigarray;;

type farray = (float, float64_elt, c_layout) Array1.t

let make_system r=
let c= r+1 in
let m= Array1.create float64 c_layout (r * c) in

let s= ref 0.0 in


for i= 0 to r-1 do
s := 0.0;
for j=0 to r-1 do

let xx = Random.float 100.0 in
( s := s.contents +. xx;
m.{i*c+j} <- xx)
done;
m.{i*c+r} <- s.contents
done;
m
;;

let iii= ref 0;;

let swapit (m:farray) c k l=


let t = ref 0.0 in
iii := iii.contents + 1;
for j=0 to c-1 do
t := Array1.get m (k*c+j);

m.{k*c+j} <- m.{l*c+j};
m.{l*c+j} <- t.contents
done
;;

let find_max (m:farray) c k idx=


let i= ref idx in
for l= k+1 to c-2 do

if (abs_float m.{l*c+k}) >
(abs_float m.{i.contents * c + k}) then


i := l
done;
if i.contents <> k then swapit m c k i.contents
;;

let solvit (mm: farray) r c=
let tx= ref 0.0 and mkk= ref 0.0 in


for k=0 to r-2 do
find_max mm c k k;

mkk := mm.{c*k + k};


for i= k+1 to r-1 do

let
rat = mm.{i*c + k} /. mkk.contents in
( for j=k to c-1 do
mm.{i*c+j} <- ( mm.{i*c+j} -.
rat *. mm.{k*c + j})
done )


done
done;
for i=r-1 downto 0 do
tx := 0.0;
for j=i+1 to r-1 do

tx := tx.contents -. mm.{i*c + j} *. mm.{j*c + r}
done;
mm.{i*c+r} <- (mm.{i*c + r} +. tx.contents) /.
mm.{i*c + i}
done
;;


let nels () =
try
int_of_string Sys.argv.(1)
with
_ -> 5000
;;

let r= nels () in
let c= (r+1) in
let mm= make_system r in
(
solvit mm r c;
for i= 0 to (min (r-1) 10) do

Printf.printf "%8.3f " mm.{i*c+r}

klohm...@yahoo.de

unread,
Dec 9, 2008, 3:33:47 AM12/9/08
to
On Dec 9, 2:54 am, phi50...@yahoo.ca wrote:

>
> Hi, George.
> In a private emails, OCAML programmers explained me how to improve the
> speed of OCAML. Now, it is only 3 times slower than Bigloo. It seems
> that I need to explicitly declare the type of arrays, in order to
> avoid polymorfism. The modified program is only three times slower
> than Scheme. BTW, people who helped me claimed that they were doing so
> privately because discussing OCAML in a Scheme list could be
> considered OT. However, I know that a lot of people write prototypes
> in Scheme, that they converto to other languages after tests.
> Therefore I do not think that translating Scheme programs to other
> languages is OT. Here is the modified OCAML program (only three times
> slower than the Scheme equivalent):

What? Why should discussing OCaml vs Bigloo be considered OT
(especially on newsgroups with only a handful of subscribers as it as
for fa.caml and comp.lang.lisp and comp.lang.scheme)? Maybe you
received some input from Germans or C language newsgroup posters.

But I am still suprised that OCaml wouldn't want to compete with
Bigloo speed wise. Why don't you post on fa.caml?

Btw: I know from experience that Bigloo scales very well for numerical
computations.

phi5...@yahoo.ca

unread,
Dec 9, 2008, 6:36:31 AM12/9/08
to

I have posted on fa.caml (no answer for the time being), and on
comp.lang.functional (four answers, one of them from J. Harrop, a well
known OCAML and numerical computation guru). Anyway, although the
suggestions increased the speed of OCAML dramatically, it is still
slow when compared with Scheme. Three times slower is too much... The
climatological models I intend to work with takes a long time to run,
and I cannot afford a slow down. I was expecting OCAML to be at least
as fast as Bigloo. In fact, I was expecting OCAML to be faster, not
slower than Bigloo. BTW, one of the suggestion was the use of 64 bits
machines. In fact, 64 bits machines speed up OCAML, but it also
increases the speed of Bigloo. Another point is that I received
suggestions to increase Bigloo's speed as well by inlining array
calls. It works for Bigloo as well, making it even faster:

(module arrays
(export (final-class f64array
v::f64vector
dimension-x::bint
dimension-y::bint)
(inline f64array-set!)
(inline f64array-ref)))

(define-inline (f64array-ref a x y)
(with-access::f64array a (v dimension-x)
(f64vector-ref v (+fx (*fx dimension-x y) x))))

(define-inline (f64array-set! a x y val)
(with-access::f64array a (v dimension-x)
(f64vector-set! v (+fx (*fx dimension-x y) x)
val)))


klohm...@yahoo.de

unread,
Dec 9, 2008, 7:09:54 AM12/9/08
to
On Dec 9, 11:36 am, phi50...@yahoo.ca wrote:

>
> (module arrays
>    (export (final-class f64array
>           v::f64vector
>           dimension-x::bint
>           dimension-y::bint)
>        (inline f64array-set!)
>        (inline f64array-ref)))
>
> (define-inline (f64array-ref a x y)
>    (with-access::f64array a (v dimension-x)
>       (f64vector-ref v (+fx (*fx dimension-x y) x))))
>
> (define-inline (f64array-set! a x y val)
>    (with-access::f64array a (v dimension-x)
>       (f64vector-set! v (+fx (*fx dimension-x y) x)
>               val)))

Hi: I know posting numbers is boring but couldn't you post some
figures of actual execution times here. Are you speaking of hours or
minutes of execution times?

Btw: you are using classses; I saw the trick on the Bigloo mailing
list first a couple of weeks ago. I would have never thought that
classes perform so well in Bigloo. I used it myself.

Silly question: why aren't you happy with Bigloo? I mean if you get
your answers way faster than in OCaml what is the point in persuading
and chasing up OCaml for speed?

klohm...@yahoo.de

unread,
Dec 9, 2008, 7:58:09 AM12/9/08
to
On Dec 9, 11:36 am, phi50...@yahoo.ca wrote:

>
> (module arrays
>    (export (final-class f64array
>           v::f64vector
>           dimension-x::bint
>           dimension-y::bint)
>        (inline f64array-set!)
>        (inline f64array-ref)))
>
> (define-inline (f64array-ref a x y)
>    (with-access::f64array a (v dimension-x)
>       (f64vector-ref v (+fx (*fx dimension-x y) x))))
>
> (define-inline (f64array-set! a x y val)
>    (with-access::f64array a (v dimension-x)
>       (f64vector-set! v (+fx (*fx dimension-x y) x)
>               val)))

I hope I am not asking for to much: but it would be cool and of much
interest to see a timing for Common Lisp code. Maybe you are
interested in in porting your code to Common Lisp and put it through
CMUCL or SBCL compiler.

I am not sure if you gonna go to post some timings. But if so could
you please post the memory consumption of the program once execution
being completed (if the programs takes a couple of minutes to run a
simple 'top' in the command line will do the trick and you could
observe the memory footprint).


Slobodan Blazeski

unread,
Dec 10, 2008, 8:26:38 AM12/10/08
to
On Dec 8, 1:02 am, phi50...@yahoo.ca wrote:
> As I told before, I use Scheme and Clean to do my homework. Usually,
> the TAs require fast and small executables (less than 1.5M). If one
> wants a good grade, his/her programs must not be much slower than the
> corresponding C code. Bigloo pretty fast, even when compared to gcc.
> However, I decided to give OCAML a try for two reasons:
>
> 1 --- Quite a few people say that it is considerably faster than
> Bigloo.
>
> 2 --- It has a nice notation for arithmetics, closer to the
> tranditional one than Bigloo.
>
> In general, a homework is a small program (200 to 300 lines), that one
> needs to apply to huge amount of data, like inverting gigantic arrays.
If you want to manipulate arrays than you are using wrong tool for the
job. Take a look at this http://www.jsoftware.com/ or this http://kx.com/
.

bobi

klohm...@yahoo.de

unread,
Dec 10, 2008, 3:54:25 PM12/10/08
to
On Dec 10, 1:26 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com>
wrote:

>
> If you want to manipulate arrays than you are using wrong tool for the
> job. Take a look at thishttp://www.jsoftware.com/or thishttp://kx.com/
> .
>
> bobi

What? Do not get me wrong but are you sure you know what your are
posting here? He? Why shouldn't be OCaml or Bigloo not being able to
cope with large arrays.

Slobodan Blazeski

unread,
Dec 11, 2008, 11:19:37 AM12/11/08
to
On Dec 10, 9:54 pm, klohmusc...@yahoo.de wrote:
> On Dec 10, 1:26 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com>
> wrote:
>
>
>
> > If you want to manipulate arrays than you are using wrong tool for the
> > job. Take a look at thishttp://www.jsoftware.com/orthishttp://kx.com/

> > .
>
> > bobi
>
> What? Do not get me wrong but are you sure you know what your are
> posting here? He? Why shouldn't be OCaml or Bigloo not being able to
> cope with large arrays.

You can't beat Array Programming language in it's own game. They were
made for doing just that, and made by one of the cs giants
http://en.wikipedia.org/wiki/Kenneth_E._Iverson Though I prefer lisp/
scheme for general programming the array programming languages are
better in certain areas and in array programming they're better BY
FAR. So fighting them would be like using general purpose weapon
against DSL. And even macros, alone, can't help you.
OCaml was always too ugly for my taste, and considering is not a
language that could either pay the bills or teach me something new I
just dumped after a month of working with it.

bobi

Benjamin L. Russell

unread,
Dec 12, 2008, 12:31:28 AM12/12/08
to
On Thu, 11 Dec 2008 08:19:37 -0800 (PST), Slobodan Blazeski
<slobodan...@gmail.com> wrote:

>OCaml was always too ugly for my taste, and considering is not a
>language that could either pay the bills or teach me something new I
>just dumped after a month of working with it.

Actually, subjectively speaking, I tend to agree with you there.

All this is just subjective opinion, and we are all entitled to our
opinions, but in particular, the double-semicolon after each line at
the REPL in OCaml always seemed very ugly to me, and I couldn't
understand why the developers couldn't just use a different character
if they couldn't use a single semicolon (or even no character). Scheme
uses parentheses, and Prolog uses a period, for example. When I stop
to think of all those billions of milliseconds collectively wasted by
OCaml developers in having to type an extra semicolon at the end of
each line in the REPL, I can't help but wonder how much extra code
they could be typing if they didn't have to type all those extra
double-semicolons. Even dust particles, if you collect enough of
them, are enough to build a mountain.

In Scheme, each parenthesis has a semantic significance is delimiting
procedures, closures, etc. But what is the significance of the second
semicolon in the double-semicolon in OCaml?

-- Benjamin L. Russell
--
Benjamin L. Russell / DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile: +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto."
-- Matsuo Basho^

namekuseijin

unread,
Feb 6, 2009, 1:34:49 PM2/6/09
to
On Dec 8 2008, 5:48 pm, phi50...@yahoo.ca wrote:
> 3 -- As for not letting my editor do the job, the reason is simple: My
> editor does not format Scheme. It has keyword coloring, and checks
> parenthesis, but that is all. I use Crimson, Texpad, and Scite. Which
> editor do you suggest? I need a small editor, since I am supposed to
> carry it in my pendrive, and erase it at the end of the class.

Carry in the pendrive and erase at the end of the class?!

Anyway, given pendrives these days are GBs worth, I guess you could
even cram Microsoft Office along with vim, SciTe, Emacs and
Eclipse. ;)

Personally, there's nothing better for Lisp/Scheme code out there than
Emacs, but I find PLT Scheme's builtin editor almost as good.

Oh, wonderful thread BTW. I thought OCaml would fare better... let
Jon Harrop know it. ;)

0 new messages