caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Camlmake.
       [not found] <000601bfe231$082d61d0$210148bf@dylan>
@ 2000-11-21 17:05 ` David Brown
  2000-11-22 16:55   ` Camlmake David Brown
  2000-11-22 21:35   ` OCaml is fast! Mattias Waldau
  0 siblings, 2 replies; 4+ messages in thread
From: David Brown @ 2000-11-21 17:05 UTC (permalink / raw)
  To: caml-list

I have thrown the source of my camlmake utility together.  This code can
compile under 3.00, but doesn't support the use of any of the new syntax.
I'm posting this in the hope that someone will be able to continue working
on this program.

This code may be distributed under the terms of either the LGPL, the GPL,
or the Q Public License version 1.0.

<http://www.davidb.org/camlmake/>

David Brown



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Camlmake.
  2000-11-21 17:05 ` Camlmake David Brown
@ 2000-11-22 16:55   ` David Brown
  2000-11-22 21:35   ` OCaml is fast! Mattias Waldau
  1 sibling, 0 replies; 4+ messages in thread
From: David Brown @ 2000-11-22 16:55 UTC (permalink / raw)
  To: caml-list

On Tue, Nov 21, 2000 at 09:05:07AM -0800, David Brown wrote:
> I have thrown the source of my camlmake utility together.  This code can
> compile under 3.00, but doesn't support the use of any of the new syntax.
> I'm posting this in the hope that someone will be able to continue working
> on this program.

I guess I should have been a little clearer in my explanation.  The code
isn't documented, or even particularly well written.  I threw it together
during the process of learning ocaml.

Think of it as a proof of concept.  This is a tool I would really like to
see available for ocaml.  The idea comes from the GNU Ada Compiler's
gnatmake utility.

If I ever come up with some time, I may write a real program to do this.  I
posted this in the hopes that someone else would take the concept and
implement the utility.  It needs a lot of work to become a generally useful
utility.

David Brown



^ permalink raw reply	[flat|nested] 4+ messages in thread

* OCaml is fast!
  2000-11-21 17:05 ` Camlmake David Brown
  2000-11-22 16:55   ` Camlmake David Brown
@ 2000-11-22 21:35   ` Mattias Waldau
  2000-11-23 13:03     ` Xavier Leroy
  1 sibling, 1 reply; 4+ messages in thread
From: Mattias Waldau @ 2000-11-22 21:35 UTC (permalink / raw)
  To: caml-list

or is my benchmark wrong? The speed is incredable, I have a 333 Mhz PII, and
Ocaml make 50 miljon round trips in the loop per second, that is 6 cycles
per loop, and in each loop one function call + add + store is done.

Or does the compiler optimize away a lot of my code? The code can be found
in the end of the file.

I made the benchmark to compare object creation + method call versus term
creation + function call. Object creation is 10 times slower, and method
calls 5 times slower. However, this difference will not be noted in a real
program unless you use objects for the smallest and most primitive objects,
like nodes in a tree and similar.

As always, I am impressed by the speed of Ocaml. However, a small superflous
';' was difficult to find, since the compiler always complained about syntax
error on the last line in the file.

----
Mattias Waldau, CTO
Tacton AB, Saltmatargatan 7, 11359 Stockholm
Mobile +46 70 549 11 12
http://www.tacton.com mailto:mattias.waldau@tacton.com


P.s. I got a tip on how to let the top level print the contents of objects -
something I complained about earlier - just define a print-method and use
#install_printer, se below

method print ff =
  Format.fprintf ff "@[with_oo:(x=%i; y=%i)@]" x y

and install it by

# let object_printer x = x #print Format.std_formatter;;
# #install_printer object_printer


(* benchmark ---------------------------------------- *)


(*
   ocamlopt.exe unix.cmxa oo_test.ml


100 000 000 loops,

2 miljons object creations + method call per second
10 miljons method calls per second

25 miljons term creations + method call per second
50 miljons function calls per second


oo with create: Run time = 51
method call only: Run time = 9
create term and call function: Run time = 4
call function: Run time = 2

*)


class with_oo =
object
  val mutable x = 0
  val mutable y = 0
  method get_x = x
  method move d = x <- x + d; y <- y + d
  method print ff =
    Format.fprintf ff "@[with_oo:(x=%i; y=%i)@]" x y
end

(*
let object_printer x = x #print Format.std_formatter;;
#install_printer object_printer
*)

let test_oo_speed () =
  for ii = 1 to 100000000 do
    (new with_oo)#move ii;
  done

let test_oo_speed_2 () =
  let obj = new with_oo in
  for ii = 1 to 100000000 do
    obj#move ii;
  done

(*
   Format.fprintf gor verkligen magiska saker, skapar functioner
   som tar olika manga argument beroende pa strangen. Men det ar
   kanske inte sa svart, eftersom de ar curried. Borde testa!!

# Format.fprintf Format.std_formatter "@[with_oo:(x=%i; y=%i)@]";;
with_oo:(x=- : int -> int -> unit = <fun>
# Format.fprintf Format.std_formatter "@[with_oo:(x=%i; y=%i; y=%i)@]";;
with_oo:(x=- : int -> int -> int -> unit = <fun>


(*

# let t = new with_oo;;
val t : with_oo = <obj>
# t;;
- : with_oo = <obj>
# t#get_x;;
- : int = 0
# t#move 10;;
- : unit = ()
# t#get_x;;
- : int = 10
#

*)

*)

type nooo = {
  mutable x:int;
  mutable y:int;
  }

let nooo_init () =
  { x=0; y=0 }

let nooo_get_x this = this.x

let nooo_move this d =
  this.x <- this.x + d;
  this.y <- this.y + d

let test_nooo_speed () =
  for ii = 1 to 100000000 do
   let term = nooo_init () in
   nooo_move term ii
  done

let test_nooo_speed_2 () =
  let term = nooo_init () in
  for ii = 1 to 100000000 do
   nooo_move term ii
  done

let profile_function text f =
   let start_time = Unix.time () in
   begin
     f ();
     print_newline ();
     print_string text;
     print_string ": Run time = ";
     print_float ((Unix.time ()) -. start_time);
   end


let _ = profile_function "oo with create" test_oo_speed
let _ = profile_function "method call only" test_oo_speed_2

let _ = profile_function "create term and call function" test_nooo_speed
let _ = profile_function "call function" test_nooo_speed_2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: OCaml is fast!
  2000-11-22 21:35   ` OCaml is fast! Mattias Waldau
@ 2000-11-23 13:03     ` Xavier Leroy
  0 siblings, 0 replies; 4+ messages in thread
From: Xavier Leroy @ 2000-11-23 13:03 UTC (permalink / raw)
  To: Mattias Waldau; +Cc: caml-list

> or is my benchmark wrong? The speed is incredable, I have a 333 Mhz PII, and
> Ocaml make 50 miljon round trips in the loop per second, that is 6 cycles
> per loop, and in each loop one function call + add + store is done.
> 
> Or does the compiler optimize away a lot of my code? The code can be found
> in the end of the file.

The functions nooo_init and nooo_move are small enough to be inlined,
so the loops in test_nooo_speed and test_nooo_speed_2 perform no
function calls.  To measure the cost of function calls, you can
disable inlining with the "-inline 0" compiler flag.

Methods are never inlined at point of call, though, because it would
require global program analysis.

One last suggestion: if you use Unix.gettimeofday instead of Unix.time,
you'll get sub-second resolution for the timings.

- Xavier Leroy



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-11-25 14:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <000601bfe231$082d61d0$210148bf@dylan>
2000-11-21 17:05 ` Camlmake David Brown
2000-11-22 16:55   ` Camlmake David Brown
2000-11-22 21:35   ` OCaml is fast! Mattias Waldau
2000-11-23 13:03     ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).