Bladeren bron

don't run timers at all if no `--times` argument given

Aleksandr Kuzmenko 6 jaren geleden
bovenliggende
commit
b5b871814e
3 gewijzigde bestanden met toevoegingen van 14 en 9 verwijderingen
  1. 5 5
      src/compiler/main.ml
  2. 0 1
      src/compiler/server.ml
  3. 9 3
      src/core/timer.ml

+ 5 - 5
src/compiler/main.ml

@@ -895,7 +895,7 @@ try
 			if String.length input > 0 && (input.[0] = '[' || input.[0] = '{') then begin
 				did_something := true;
 				force_typing := true;
-				DisplayJson.parse_input com input measure_times
+				DisplayJson.parse_input com input Timer.measure_times
 			end else
 				DisplayOutput.handle_display_argument com input pre_compilation did_something;
 		),"","display code tips");
@@ -906,7 +906,7 @@ try
 			json_out := Some file
 		),"<file>","generate JSON types description");
 		("Optimization",["--no-output"],[], Arg.Unit (fun() -> no_output := true),"","compiles but does not generate any file");
-		("Debug",["--times"],[], Arg.Unit (fun() -> measure_times := true),"","measure compilation times");
+		("Debug",["--times"],[], Arg.Unit (fun() -> Timer.measure_times := true),"","measure compilation times");
 		("Optimization",["--no-inline"],[], define Define.NoInline, "","disable inlining");
 		("Optimization",["--no-opt"],[], Arg.Unit (fun() ->
 			com.foptimize <- false;
@@ -1125,7 +1125,7 @@ with
 		raise (DisplayOutput.Completion (String.concat "." pack))
 	| DisplayException(DisplayFields Some r) ->
 		DisplayPosition.display_position#reset;
-		let fields = if !measure_times then begin
+		let fields = if !Timer.measure_times then begin
 			Timer.close_times();
 			(List.map (fun (name,value) ->
 				CompletionItem.make_ci_timer ("@TIME " ^ name) value
@@ -1203,7 +1203,7 @@ with
 		raise (DisplayOutput.Completion s)
 	| EvalExceptions.Sys_exit i | Hlinterp.Sys_exit i ->
 		ctx.flush();
-		if !measure_times then Timer.report_times prerr_endline;
+		if !Timer.measure_times then Timer.report_times prerr_endline;
 		exit i
 	| DisplayOutput.Completion _ as exc ->
 		raise exc
@@ -1232,4 +1232,4 @@ with DisplayOutput.Completion c ->
 	exit 1
 );
 other();
-if !measure_times then Timer.report_times prerr_endline
+if !Timer.measure_times then Timer.report_times prerr_endline

+ 0 - 1
src/compiler/server.ml

@@ -12,7 +12,6 @@ open Json
 exception Dirty of path
 exception ServerError of string
 
-let measure_times = ref false
 let prompt = ref false
 let start_time = ref (Timer.get_time())
 

+ 9 - 3
src/core/timer.ml

@@ -25,6 +25,8 @@ type timer_infos = {
 	mutable calls : int;
 }
 
+let measure_times = ref false
+
 let get_time = Extc.time
 let htimers = Hashtbl.create 0
 
@@ -68,9 +70,13 @@ let rec close now t =
 			close now tt
 
 let timer id =
-	let t = new_timer id in
-	curtime := t :: !curtime;
-	(function() -> close (get_time()) t)
+	if !measure_times then (
+		let t = new_timer id in
+		curtime := t :: !curtime;
+		(function() -> close (get_time()) t)
+	) else
+		(fun() -> ())
+
 
 let rec close_times() =
 	let now = get_time() in