[UDF] Improve performance of function money_format (#4672)

Use static local variable instead of create it every calls.
Time cost of the new added unit benchmark test could reduce
from about 60 seconds to 10 seconds.
This commit is contained in:
Yingchun Lai
2020-09-28 13:39:41 +08:00
committed by GitHub
parent 0eb54007be
commit b1853caeed
2 changed files with 20 additions and 3 deletions

View File

@ -41,6 +41,16 @@ private:
FunctionContext* ctx;
};
TEST_F(StringFunctionsTest, do_money_format_bench) {
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
StringVal expected = AnyValUtil::from_string_temp(context, std::string("9,223,372,036,854,775,807.00"));
for (int i = 0; i < 10000000; i++) {
StringVal result = StringFunctions::do_money_format(context, "922337203685477580700"); // cent
ASSERT_EQ(expected, result);
}
delete context;
}
TEST_F(StringFunctionsTest, money_format_bigint) {
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();