5 ms·
Have a link to benchmarks where Ocaml beats C? In my experience Ocaml is usually only about 2x slower than C, but never beating it. Also, Ocaml is statically ty
by sausagefeet 15y ago
Have a link to benchmarks where Ocaml beats C? In my experience Ocaml is usually only about 2x slower than C, but never beating it. Also, Ocaml is statically typed. Type inference is just inferring the static types.
- fleitz 15y agohttp://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=gcc&lang2=ocaml http://shootout.alioth.debian.org/u32/benchmark.php?test=all... http://flyingfrogblog.blogspot.com/2009/07/ocaml-vs-f-burrows-wheeler.html http://flyingfrogblog.blogspot.com/2009/07/ocaml-vs-f-burrow... You're right about OCaml generally being 1.5X slower than C but it does beat it for some problems which is impressive for all the additional features it provides. I must have been looking at the numbers wrong last time I checked. Type inference is much different than static typing because it allows functions to be specialized at run/compile time which can result in having to write much less code. For example, in C a map function would have to be written for every datatype (or lose the benefits of static typing by using a void*) where as in OCaml/F# you get type safety and specialized / inlined code for free.
- sausagefeet 15y ago> Type inference is much different than static typing because it allows functions to be specialized at run/compile time which can result in having to write much less code. You are confused, type inference is purely about determining what type something is. It can determine a function is polymorphic but this has nothing to do with how the polymorphism is implemented. AFAIK Ocaml (by that I mean the INRIA Ocaml implementation) doesn't specialize polymorphic functions at all. Types are boxed and the boxes are all the same size so a single function definition is all that is needed for a polymorphic function or type. .net does do these things but, again, that has nothing to do with type inference. There is no difference between me specifying a function has type 'a -> 'b and the compiler inferring that.
- Locke1689 15y agoThis is correct. The most common algorithm used for type inference is Hindley-Milner (http://en.wikipedia.org/wiki/Hindley%E2%80%93Milner http://en.wikipedia.org/wiki/Hindley%E2%80%93Milner).
- jamii 15y agoI've never seen Ocaml come even close to C in micro-benchmarks but in large applications it can win on macro-optimisations eg Deens is significantly faster than BIND with much less code (www.utdallas.edu/~hamlen/Slides/Melange.pdf)