From c358fff57f0cb52c16e67596d316c66b737d604f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 9 Feb 2011 12:09:57 -0800 Subject: [PATCH] Cache decoding objects for better benchmark results. (~15%) I would prefer to find an API that is both fast and doesn't require this, but we'll do this for now. --- benchmarks/parsetostruct.upb_table.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/benchmarks/parsetostruct.upb_table.c b/benchmarks/parsetostruct.upb_table.c index dfdad3657d..406229b782 100644 --- a/benchmarks/parsetostruct.upb_table.c +++ b/benchmarks/parsetostruct.upb_table.c @@ -10,6 +10,10 @@ static upb_string *input_str; static upb_msgdef *def; static upb_msg *msg; +static upb_stringsrc strsrc; +static upb_decoder d; +static upb_handlers h; +static upb_msgpopulator p; static bool initialize() { @@ -49,6 +53,11 @@ static bool initialize() } upb_status_uninit(&status); msg = upb_msg_new(def); + + upb_stringsrc_init(&strsrc); + upb_decoder_init(&d, def); + upb_msgpopulator_init(&p); + upb_handlers_init(&h); return true; } @@ -57,6 +66,10 @@ static void cleanup() upb_string_unref(input_str); upb_msg_unref(msg, def); upb_def_unref(UPB_UPCAST(def)); + upb_stringsrc_uninit(&strsrc); + upb_decoder_uninit(&d); + upb_msgpopulator_uninit(&p); + upb_handlers_uninit(&h); } static size_t run(int i) @@ -64,7 +77,15 @@ static size_t run(int i) (void)i; upb_status status = UPB_STATUS_INIT; upb_msg_clear(msg, def); - upb_strtomsg(input_str, msg, def, &status); + upb_stringsrc_reset(&strsrc, input_str); + upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc)); + upb_msgpopulator_reset(&p, msg, def); + upb_handlers_init(&h); + upb_msgpopulator_register_handlers(&p, &h); + upb_src *src = upb_decoder_src(&d); + upb_src_sethandlers(src, &h); + + upb_src_run(src, &status); if(!upb_ok(&status)) goto err; upb_status_uninit(&status); return upb_string_len(input_str);