diff --git a/master_changes.md b/master_changes.md index 33c82c40394..170e89c9012 100644 --- a/master_changes.md +++ b/master_changes.md @@ -103,6 +103,7 @@ users) ## Test ## Benchmarks + * Add benchmarks for `opam show` [#6212 @kit-ty-kate] ## Reftests ### Tests diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index dcc75638677..83e2fa26fa3 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -692,9 +692,27 @@ module OpamString = struct let rcut_at = cut_at_aux String.rindex let split s c = - (* old compat version (Re 1.2.0) - {[Re_str.split (Re_str.regexp (Printf.sprintf "[%c]+" c)) s]} *) - Re.(split (compile (rep1 (char c)))) s + let rec loop acc in_run slice_start len i s c = + if (i : int) < (len : int) then + if (String.get s i : char) = (c : char) then + if not in_run then + if (i : int) > (slice_start : int) then + loop (String.sub s slice_start (i - slice_start) :: acc) + true slice_start len (i + 1) s c + else + loop acc true slice_start len (i + 1) s c + else + loop acc in_run slice_start len (i + 1) s c + else if in_run then + loop acc false i len (i + 1) s c + else + loop acc in_run slice_start len (i + 1) s c + else if not in_run && (slice_start : int) < (len : int) then + String.sub s slice_start (len - slice_start) :: acc + else + acc + in + List.rev (loop [] false 0 (String.length s) 0 s c) let split_delim s c = let tokens = Re.(split_full (compile (char c)) s) in diff --git a/tests/bench/bench.ml b/tests/bench/bench.ml index d55c07edcee..4bb6d9f08fd 100644 --- a/tests/bench/bench.ml +++ b/tests/bench/bench.ml @@ -99,6 +99,24 @@ let () = launch (fmt "%s switch create six --empty" bin); time_cmd ~exit:0 (fmt "%s list --installed --short --safe --color=never ocp-indent ocp-index merlin" bin) in + launch (fmt "%s switch create seven --empty" bin); + launch (fmt "%s install -y --fake dune" bin); + let time_show_installed = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show dune" bin) + in + let time_show_with_depexts = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show conf-pkg-config" bin) + in + let time_show_raw = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show --raw conf-pkg-config" bin) + in + let time_show_precise = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show --raw conf-pkg-config.2" bin) + in let json = fmt {|{ "results": [ { @@ -148,6 +166,26 @@ let () = "name": "opam list --installed on non-installed packages", "value": %f, "units": "secs" + }, + { + "name": "opam show of an installed package", + "value": %f, + "units": "secs" + }, + { + "name": "opam show with depexts", + "value": %f, + "units": "secs" + }, + { + "name": "opam show --raw pkgname", + "value": %f, + "units": "secs" + }, + { + "name": "opam show --raw pkgname.version", + "value": %f, + "units": "secs" } ] }, @@ -172,6 +210,10 @@ let () = time_install_check_installed time_install_check_not_installed time_list_installed_noninstalled_packages + time_show_installed + time_show_with_depexts + time_show_raw + time_show_precise bin_size in print_endline json