diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/tests/eina_bench_convert.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/tests/eina_bench_convert.c')
-rw-r--r-- | libraries/eina/src/tests/eina_bench_convert.c | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_bench_convert.c b/libraries/eina/src/tests/eina_bench_convert.c new file mode 100644 index 0000000..aafe9ea --- /dev/null +++ b/libraries/eina/src/tests/eina_bench_convert.c | |||
@@ -0,0 +1,183 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include "config.h" | ||
21 | #endif | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <time.h> | ||
26 | #include <math.h> | ||
27 | |||
28 | #ifdef EINA_BENCH_HAVE_GLIB | ||
29 | # include <glib.h> | ||
30 | #endif | ||
31 | |||
32 | #include "eina_bench.h" | ||
33 | #include "eina_convert.h" | ||
34 | |||
35 | static void | ||
36 | eina_bench_convert_itoa_10(int request) | ||
37 | { | ||
38 | char tmp[128]; | ||
39 | int i; | ||
40 | |||
41 | srand(time(NULL)); | ||
42 | |||
43 | for (i = 0; i < request; ++i) | ||
44 | { | ||
45 | eina_convert_itoa(rand(), tmp); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | static void | ||
50 | eina_bench_convert_itoa_16(int request) | ||
51 | { | ||
52 | char tmp[128]; | ||
53 | int i; | ||
54 | |||
55 | srand(time(NULL)); | ||
56 | |||
57 | for (i = 0; i < request; ++i) | ||
58 | { | ||
59 | eina_convert_xtoa(rand(), tmp); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | static void | ||
64 | eina_bench_convert_snprintf_10(int request) | ||
65 | { | ||
66 | char tmp[128]; | ||
67 | int i; | ||
68 | |||
69 | srand(time(NULL)); | ||
70 | |||
71 | for (i = 0; i < request; ++i) | ||
72 | { | ||
73 | snprintf(tmp, 128, "%i", rand()); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | static void | ||
78 | eina_bench_convert_snprintf_x(int request) | ||
79 | { | ||
80 | char tmp[128]; | ||
81 | int i; | ||
82 | |||
83 | srand(time(NULL)); | ||
84 | |||
85 | for (i = 0; i < request; ++i) | ||
86 | { | ||
87 | snprintf(tmp, 128, "%x", rand()); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | static void | ||
92 | eina_bench_convert_snprintf_a(int request) | ||
93 | { | ||
94 | char tmp[128]; | ||
95 | double r; | ||
96 | int i; | ||
97 | |||
98 | srand(time(NULL)); | ||
99 | |||
100 | for (i = 0; i < request; ++i) | ||
101 | { | ||
102 | r = 10000 * (rand() / ((double)RAND_MAX + 1)); | ||
103 | snprintf(tmp, 128, "%a", r); | ||
104 | sscanf(tmp, "%la", &r); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | static void | ||
109 | eina_bench_convert_dtoa(int request) | ||
110 | { | ||
111 | char tmp[128]; | ||
112 | long long m; | ||
113 | long e; | ||
114 | double r; | ||
115 | int i; | ||
116 | |||
117 | srand(time(NULL)); | ||
118 | |||
119 | for (i = 0; i < request; ++i) | ||
120 | { | ||
121 | r = 10000 * (rand() / ((double)RAND_MAX + 1)); | ||
122 | eina_convert_dtoa(r, tmp); | ||
123 | eina_convert_atod(tmp, 128, &m, &e); | ||
124 | r = ldexp((double)m, e); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | #ifdef EINA_BENCH_HAVE_GLIB | ||
129 | static void | ||
130 | eina_bench_convert_gstrtod(int request) | ||
131 | { | ||
132 | char tmp[128]; | ||
133 | double r; | ||
134 | int i; | ||
135 | |||
136 | srand(time(NULL)); | ||
137 | |||
138 | for (i = 0; i < request; ++i) | ||
139 | { | ||
140 | r = 10000 * (rand() / ((double)RAND_MAX + 1)); | ||
141 | g_ascii_dtostr(tmp, 128, r); | ||
142 | r = g_ascii_strtod(tmp, NULL); | ||
143 | } | ||
144 | } | ||
145 | #endif | ||
146 | |||
147 | void eina_bench_convert(Eina_Benchmark *bench) | ||
148 | { | ||
149 | eina_benchmark_register(bench, "itoa 10", | ||
150 | EINA_BENCHMARK( | ||
151 | eina_bench_convert_itoa_10), 1000, 200000, | ||
152 | 500); | ||
153 | eina_benchmark_register(bench, "itoa 16", | ||
154 | EINA_BENCHMARK( | ||
155 | eina_bench_convert_itoa_16), 1000, 200000, | ||
156 | 500); | ||
157 | eina_benchmark_register(bench, "snprintf 10", | ||
158 | EINA_BENCHMARK( | ||
159 | eina_bench_convert_snprintf_10), 1000, 200000, | ||
160 | 500); | ||
161 | eina_benchmark_register(bench, "snprintf 16", | ||
162 | EINA_BENCHMARK( | ||
163 | eina_bench_convert_snprintf_x), 1000, 200000, | ||
164 | 500); | ||
165 | eina_benchmark_register(bench, "snprintf a", | ||
166 | EINA_BENCHMARK( | ||
167 | eina_bench_convert_snprintf_a), 1000, 200000, | ||
168 | 500); | ||
169 | eina_benchmark_register(bench, "dtoa", | ||
170 | EINA_BENCHMARK( | ||
171 | eina_bench_convert_dtoa), 1000, 200000, | ||
172 | 500); | ||
173 | #ifdef EINA_BENCH_HAVE_GLIB | ||
174 | eina_benchmark_register(bench, "gstrtod", | ||
175 | EINA_BENCHMARK( | ||
176 | eina_bench_convert_gstrtod), 1000, 200000, | ||
177 | 500); | ||
178 | #endif | ||
179 | } | ||
180 | |||
181 | |||
182 | |||
183 | |||