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.
pull/13171/head
Joshua Haberman 14 years ago
parent f858a8f287
commit c358fff57f
  1. 23
      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);

Loading…
Cancel
Save