1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL AB
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/error.h>
22
#include <drizzled/session.h>
26
class BenchmarkFunction :public Item_int_func
29
BenchmarkFunction() :Item_int_func() {}
31
virtual void print(String *str, enum_query_type query_type);
33
const char *func_name() const
38
void fix_length_and_dec()
44
bool check_argument_count(int n)
51
/* This function is just used to test speed of different functions */
52
int64_t BenchmarkFunction::val_int()
54
assert(fixed == true);
56
char buff[MAX_FIELD_WIDTH];
57
String tmp(buff,sizeof(buff), &my_charset_bin);
58
my_decimal tmp_decimal;
59
Session *session= current_session;
62
loop_count= (uint64_t) args[0]->val_int();
64
if (args[0]->null_value ||
65
(args[0]->unsigned_flag == false && (((int64_t) loop_count) < 0)))
67
if (args[0]->null_value == false)
69
llstr(((int64_t) loop_count), buff);
70
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
71
ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
72
"count", buff, "benchmark");
82
for (loop= 0 ; loop < loop_count && !session->killed; loop++)
84
switch (args[1]->result_type())
87
(void) args[1]->val_real();
90
(void) args[1]->val_int();
93
(void) args[1]->val_str(&tmp);
96
(void) args[1]->val_decimal(&tmp_decimal);
100
// This case should never be chosen
108
void BenchmarkFunction::print(String *str, enum_query_type query_type)
110
str->append(STRING_WITH_LEN("benchmark("));
111
args[0]->print(str, query_type);
113
args[1]->print(str, query_type);
117
Create_function<BenchmarkFunction> benchmarkudf(string("benchmark"));
119
static int initialize(PluginRegistry ®istry)
121
registry.add(&benchmarkudf);
125
static int finalize(PluginRegistry ®istry)
127
registry.remove(&benchmarkudf);
131
drizzle_declare_plugin(benchmark)
135
"Devananda van der Veen",
136
"Measure time for repeated calls to a function.",
138
initialize, /* Plugin Init */
139
finalize, /* Plugin Deinit */
140
NULL, /* status variables */
141
NULL, /* system variables */
142
NULL /* config options */
144
drizzle_declare_plugin_end;