157 #include <boost/lexical_cast.hpp>
158 #include <gutil/strings/substitute.h>
169 using namespace impala;
170 using namespace impala_udf;
171 using namespace strings;
181 string* s =
new string();
182 *s = lexical_cast<
string>(v);
183 return StringVal(reinterpret_cast<uint8_t*>(const_cast<char*>(s->c_str())), s->size());
188 template<
typename T,
typename SetType>
202 template<
typename T,
typename SetType>
207 data.
anyvals.resize(num_values);
209 for (
int i = 0; i < num_values; ++i) {
210 data.
anyvals[i] = MakeAnyVal<T>(rand());
214 for (
int i = 0; i < num_search_vals; ++i) {
220 vector<AnyVal*> constant_args;
221 constant_args.push_back(NULL);
223 UdfTestHarness::SetConstantArgs(ctx, constant_args);
225 InPredicate::SetLookupPrepare<T, SetType>(ctx, FunctionContext::FRAGMENT_LOCAL);
227 ctx->GetFunctionState(FunctionContext::FRAGMENT_LOCAL));
233 template<
typename T,
typename SetType>
236 for (
int i = 0; i < batch_size; ++i) {
237 BOOST_FOREACH(
const T& search_val, data->
search_vals) {
245 template<
typename T,
typename SetType>
248 for (
int i = 0; i < batch_size; ++i) {
249 BOOST_FOREACH(
const T& search_val, data->
search_vals) {
259 Benchmark suite(Substitute(
"int n=$0", n));
263 InPredicateBenchmark::CreateTestData<IntVal, int32_t>(n, type);
265 InPredicateBenchmark::TestSetLookup<IntVal, int32_t>, &data);
267 InPredicateBenchmark::TestIterate<IntVal, int32_t>, &data);
268 cout << suite.
Measure() << endl;
274 Benchmark suite(Substitute(
"string n=$0", n));
278 InPredicateBenchmark::CreateTestData<StringVal, StringValue>(n, type);
280 InPredicateBenchmark::TestSetLookup<StringVal, StringValue>, &data);
282 InPredicateBenchmark::TestIterate<StringVal, StringValue>, &data);
283 cout << suite.
Measure() << endl;
289 Benchmark suite(Substitute(
"decimal(4,0) n=$0", n));
295 InPredicateBenchmark::CreateTestData<DecimalVal, Decimal16Value>(n, type);
297 InPredicateBenchmark::TestSetLookup<DecimalVal, Decimal16Value>, &data);
299 InPredicateBenchmark::TestIterate<DecimalVal, Decimal16Value>, &data);
300 cout << suite.
Measure() << endl;
308 vector<FunctionContext::TypeDesc> arg_types(num_args + 1, type);
309 return UdfTestHarness::CreateTestContext(ret_type, arg_types);
316 int main(
int argc,
char **argv) {
int precision
Only valid if type == TYPE_DECIMAL.
int AddBenchmark(const std::string &name, BenchmarkFunction fn, void *args, int baseline_idx=0)
static void TestIterate(int batch_size, void *d)
static std::string GetMachineInfo()
Output machine/build configuration as a string.
static BooleanVal Iterate(const FunctionContext::TypeDesc *type, const T &val, int num_args, const T *args)
Iterates through each vararg looking for val. 'type' is the type of 'val' and 'args'.
std::string Measure()
Runs all the benchmarks and returns the result in a formatted string.
static FunctionContext * CreateContext(int num_args, const FunctionContext::TypeDesc &type)
int main(int argc, char **argv)
static BooleanVal SetLookup(SetLookupState< SetType > *state, const T &v)
Looks up v in state->val_set.
static void TestSetLookup(int batch_size, void *d)
vector< AnyVal * > anyval_ptrs
static void RunIntBenchmark(int n)
static TestData< T, SetType > CreateTestData(int num_values, const FunctionContext::TypeDesc &type, int num_search_vals=100)
static void RunDecimalBenchmark(int n)
static void Init()
Initialize CpuInfo.
InPredicate::SetLookupState< SetType > state
static void RunStringBenchmark(int n)