caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] What is the fastest? Pattern matching or if then else
@ 2012-12-07  2:33 Francois Berenger
  2012-12-07  2:45 ` Jacques Garrigue
       [not found] ` <20121207.090650.972729327013546587.Christophe.Troestler@umons.ac.be>
  0 siblings, 2 replies; 5+ messages in thread
From: Francois Berenger @ 2012-12-07  2:33 UTC (permalink / raw)
  To: caml-list

Hello,

I always wondered what is the fastest (at least for integers):

match n with
   0 -> (* do something *)
| _ -> (* do something else *)

or

if n = 0 then
   (* do something *)
else
   (* do something else *)

Sometimes I have some code that would be more beautiful
if I was using only pattern matching rather than
pattern matching interspersed with if then else directives.

Is one significantly faster than the other?

Is it the same cost at runtime?

Thanks a lot,
F.

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

end of thread, other threads:[~2012-12-10  0:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-07  2:33 [Caml-list] What is the fastest? Pattern matching or if then else Francois Berenger
2012-12-07  2:45 ` Jacques Garrigue
2012-12-07  9:28   ` Christos KK Loverdos
     [not found] ` <20121207.090650.972729327013546587.Christophe.Troestler@umons.ac.be>
2012-12-10  0:06   ` Francois Berenger
     [not found]     ` <20121210.012739.1808775350475077852.Christophe.Troestler@umons.ac.be>
2012-12-10  0:44       ` Francois Berenger

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).