2
-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
6
#include <drizzled/server_includes.h>
7
#include <drizzled/error.h>
8
#include <drizzled/session.h>
12
class Item_func_benchmark :public Item_int_func
15
// Item_func_benchmark(Item *count_expr, Item *expr) :Item_int_func(count_expr, expr) {}
16
Item_func_benchmark() :Item_int_func() {}
18
virtual void print(String *str, enum_query_type query_type);
20
const char *func_name() const { return "benchmark"; }
21
void fix_length_and_dec() { max_length=1; maybe_null=0; }
22
bool check_argument_count(int n) { return (n==2); }
26
/* This function is just used to test speed of different functions */
27
int64_t Item_func_benchmark::val_int()
30
char buff[MAX_FIELD_WIDTH];
31
String tmp(buff,sizeof(buff), &my_charset_bin);
32
my_decimal tmp_decimal;
33
Session *session=current_session;
36
loop_count= (uint64_t) args[0]->val_int();
38
if (args[0]->null_value ||
39
(!args[0]->unsigned_flag && (((int64_t) loop_count) < 0)))
41
if (!args[0]->null_value)
43
llstr(((int64_t) loop_count), buff);
44
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
45
ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
46
"count", buff, "benchmark");
54
for (uint64_t loop=0 ; loop < loop_count && !session->killed; loop++)
56
switch (args[1]->result_type()) {
58
(void) args[1]->val_real();
61
(void) args[1]->val_int();
64
(void) args[1]->val_str(&tmp);
67
(void) args[1]->val_decimal(&tmp_decimal);
71
// This case should never be chosen
79
void Item_func_benchmark::print(String *str, enum_query_type query_type)
81
str->append(STRING_WITH_LEN("benchmark("));
82
args[0]->print(str, query_type);
84
args[1]->print(str, query_type);
88
Create_function<Item_func_benchmark> benchmarkudf(string("benchmark"));
90
static int initialize(PluginRegistry ®istry)
92
registry.add(&benchmarkudf);
96
drizzle_declare_plugin(benchmark)
100
"Devananda van der Veen",
101
"Measure time for repeated calls to a function.",
103
initialize, /* Plugin Init */
104
NULL, /* Plugin Deinit */
105
NULL, /* status variables */
106
NULL, /* system variables */
107
NULL /* config options */
109
drizzle_declare_plugin_end;