realworldocaml / examples

All the examples in Real World OCaml
The Unlicense
376 stars 81 forks source link

Change in Core_bench interface? #37

Open samrat opened 9 years ago

samrat commented 9 years ago

I'm trying to run the code in https://github.com/realworldocaml/examples/blob/master/code/lists-and-patterns/main.topscript#L62. However, it looks like the type signature of Bench.bench has changed since the example was written:

utop[6]> #require "core_bench";;
utop[7]> open Core_bench.Std;;
utop[8]> Bench.bench;;
- : ?run_config:Bench.Run_config.t ->
    ?analysis_configs:Bench.Analysis_config.t list ->
    ?display_config:Bench.Display_config.t ->
    ?save_to_file:(Bench.Measurement.t -> bytes) ->
    Core_bench.Test.t list -> unit
= <fun>
utop[9]> let run_bench tests =
  Bench.bench
    ~ascii_table:true
    ~display:Textutils.Ascii_table.Display.column_titles
    tests
;;
Error: The function applied to this argument has type
         ?run_config:Bench.Run_config.t ->
         ?analysis_configs:Bench.Analysis_config.t list ->
         ?display_config:Bench.Display_config.t ->
         ?save_to_file:(Bench.Measurement.t -> bytes) -> unit
This argument cannot be applied with label ~ascii_table
utop[10]> 

The core_bench version I have installed is 112.35.00

samrat commented 9 years ago

I believe this is what the run_bench function should look like:

let run_bench tests =
           Command.run (Bench.make_command tests);;
seungjin commented 9 years ago

What about this? :-) Core_bench version: 109.58.01

let display_config = Bench.Display_config.create
                       ~display:Textutils.Ascii_table.Display.column_titles
                       ~ascii_table:true
                       ~show_percentage:true
                       ()
;;

let run_bench tests =
  Bench.bench
  ~display_config:display_config
  tests
;;

Also commented here: https://github.com/realworldocaml/book/issues/2714

zzhjerry commented 8 years ago

If someone doesn't care about the display style, using Bench.bench is also fine.

[ Bench.Test.create ~name:"plus_one_match" (fun () ->
      ignore (plus_one_match 10))
  ; Bench.Test.create ~name:"plus_one_if" (fun () ->
      ignore (plus_one_if 10)) ]
  |> Bench.bench
  ;;