Commit 654e9227 authored by POTTIER Francois's avatar POTTIER Francois

Added tests [if log] so as to diminish the cost of logging when it is OFF.

I see a 5% performance gain, from 2.0 to 1.9.
If we could remove the tests altogether, we would go down to 1.8.
parent d3d469e6
......@@ -6,7 +6,7 @@
remove ocamldep.wrapper? remove OMakefiles
* Voir si ça coûte cher de stocker la taille de la pile dans
chaque cellule; voir si les appels à Log coûtent cher
chaque cellule
* Could we avoid a special case for the first call to read()?
......@@ -69,7 +69,8 @@ module Make (T : TABLE) = struct
(* Log the fact that we just entered this state. *)
Log.state env.current;
if log then
Log.state env.current;
(* If [please_discard] is set, discard a token and fetch the next one.
This is done by jumping to [discard], which itself will jump to
......@@ -87,8 +88,10 @@ module Make (T : TABLE) = struct
and discard env =
let triple = in
let (token, startp, endp) = triple in
Log.lookahead_token (T.token2terminal token) startp endp;
if log then begin
let (token, startp, endp) = triple in
Log.lookahead_token (T.token2terminal token) startp endp
let env = { env with triple } in
check_for_default_reduction env
......@@ -118,7 +121,8 @@ module Make (T : TABLE) = struct
let (token, _, _) = env.triple in
if token == error_token then begin
if log then
error env
......@@ -153,7 +157,8 @@ module Make (T : TABLE) = struct
(* Log the transition. *)
Log.shift terminal s';
if log then
Log.shift terminal s';
(* Push a new cell onto the stack, containing the identity of the
state that we are leaving. *)
......@@ -183,7 +188,8 @@ module Make (T : TABLE) = struct
(* Log a reduction event. *)
Log.reduce_or_accept prod;
if log then
Log.reduce_or_accept prod;
(* Invoke the semantic action. The semantic action is responsible for
truncating the stack and pushing a new cell onto the stack, which
......@@ -230,6 +230,13 @@ module type TABLE = sig
(* The comments below indicate the conventional messages that correspond
to these hooks in the code-based back-end; see [CodeBackend]. *)
(* If the flag [log] is false, then the logging functions are guaranteed
to do nothing, so it is not necessary to call them. If [log] is true,
the logging functions may or may not have an effect. This flag is
logically superfluous, but saves time in the table-based back-end. *)
val log : bool
module Log : sig
(* State %d: *)
......@@ -168,6 +168,8 @@ module T = struct
next = !stack
let log = true
module Log = struct
open Printf
......@@ -102,6 +102,11 @@ module Make (T : TableFormat.TABLES)
let semantic_action prod =
(* If [T.trace] is [None], then the logging functions do nothing. *)
let log =
match T.trace with Some _ -> true | None -> false
module Log = struct
open Printf
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment