2 * fribidi-benchmark.c - command line benchmark tool for libfribidi
5 * Behdad Esfahbod, 2001, 2002, 2004
6 * Dov Grobgeld, 1999, 2000
8 * Copyright (C) 2004 Sharif FarsiWeb, Inc
9 * Copyright (C) 2001,2002 Behdad Esfahbod
10 * Copyright (C) 1999,2000 Dov Grobgeld
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library, in a file named COPYING; if not, write to the
24 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA
27 * For licensing issues, contact <fribidi.license@gmail.com>.
33 #include <fribidi-deprecated.h>
45 # if !STDC_HEADERS && HAVE_MEMORY_H
53 #ifdef HAVE_SYS_TIMES_H
54 # include <sys/times.h>
62 #define appname "fribidi_benchmark"
64 #define MAX_STR_LEN 1000
73 fprintf (stderr, "%s: ", appname);
75 fprintf (stderr, fmt, arg);
76 fprintf (stderr, "Try `%s --help' for more information.\n", appname);
81 "a THE QUICK -123,456 (FOX JUMPS ) DOG the quick !1@7#4&5^ over the dog " \
82 "123,456 OVER THE 5%+ 4.0 LAZY"
83 #define TEST_STRING_EXPLICIT \
84 "this is _LJUST_o a _lsimple _Rte%ST_o th_oat HAS A _LPDF missing" \
85 "AnD hOw_L AbOuT, 123,987 tHiS_o a GO_oOD - _L_oTE_oST. " \
86 "here_L is_o_o_o _R a good one_o And _r 123,987_LT_oHE_R next_o oNE:" \
87 "_R_r and the last _LONE_o IS THE _rbest _lONE and" \
88 "a _L_L_L_LL_L_L_L_L_L_L_L_L_Rbug_o_o_o_o_o_o" \
89 "_R_r and the last _LONE_o IS THE _rbest _lONE and" \
90 "A REAL BIG_l_o BUG! _L _l_r_R_L_laslaj siw_o_Rlkj sslk" \
91 "a _L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_L_Rbug" \
92 "here_L is_o_o_o _R ab one_o _r 123,987_LT_oHE_R t_o oNE:" \
100 ("Usage: " appname " [OPTION]...\n"
101 "A program for benchmarking the speed of the " FRIBIDI_NAME
103 " -h, --help Display this information and exit\n"
104 " -V, --version Display version information and exit\n"
105 " -n, --niter N Number of iterations. Default is %d.\n"
106 "\nReport bugs online at\n<" FRIBIDI_BUGREPORT ">.\n", NUM_ITER);
115 printf (appname " %s", fribidi_version_info);
125 FILETIME creationTime, exitTime, kernelTime, userTime;
126 HANDLE currentProcess = GetCurrentProcess();
127 if (GetProcessTimes(currentProcess, &creationTime, &exitTime, &kernelTime, &userTime))
129 unsigned __int64 myTime = userTime.dwHighDateTime;
130 myTime = (myTime << 32) | userTime.dwLowDateTime;
131 return 1e-7 * myTime;
136 #ifdef HAVE_SYS_TIMES_H
139 return 0.01 * tb.tms_utime;
141 #warning Please fill in here to use other functions for determining time.
154 FriBidiChar us[MAX_STR_LEN], out_us[MAX_STR_LEN];
155 FriBidiStrIndex positionLtoV[MAX_STR_LEN], positionVtoL[MAX_STR_LEN];
156 FriBidiLevel embedding_list[MAX_STR_LEN];
163 for (i = 0, j = 0; i < len; i++)
169 us[j++] = FRIBIDI_CHAR_LRM;
172 us[j++] = FRIBIDI_CHAR_RLM;
175 us[j++] = FRIBIDI_CHAR_LRE;
178 us[j++] = FRIBIDI_CHAR_RLE;
181 us[j++] = FRIBIDI_CHAR_LRO;
184 us[j++] = FRIBIDI_CHAR_RLO;
187 us[j++] = FRIBIDI_CHAR_PDF;
199 if (us[j] >= 'A' && us[j] <= 'F')
200 us[j] += FRIBIDI_CHAR_ARABIC_ALEF - 'A';
201 else if (us[j] >= 'G' && us[j] <= 'Z')
202 us[j] += FRIBIDI_CHAR_HEBREW_ALEF - 'G';
203 else if (us[j] >= '6' && us[j] <= '9')
204 us[j] += FRIBIDI_CHAR_ARABIC_ZERO - '0';
212 for (i = 0; i < niter; i++)
214 /* Create a bidi string */
215 base = FRIBIDI_PAR_ON;
216 FRIBIDI_BEGIN_IGNORE_DEPRECATIONS
217 if (!fribidi_log2vis (us, len, &base,
219 out_us, positionVtoL, positionLtoV,
222 ("something failed in fribidi_log2vis.\n"
223 "perhaps memory allocation failure.", NULL);
224 FRIBIDI_END_IGNORE_DEPRECATIONS
231 printf ("Length = %d\n", len);
232 printf ("Iterations = %d\n", niter);
233 printf ("%d len*iterations in %f seconds\n", len * niter, time1 - time0);
234 printf ("= %.0f kilo.length.iterations/second\n",
235 1.0 * len * niter / 1000 / (time1 - time0));
246 int niter = NUM_ITER;
248 /* Parse the command line */
252 int option_index = 0, c;
253 static struct option long_options[] = {
255 {"version", 0, 0, 'V'},
256 {"niter", 0, 0, 'n'},
260 c = getopt_long (argc, argv, "hVn:", long_options, &option_index);
275 niter = atoi (optarg);
277 die2 ("invalid number of iterations `%s'\n", optarg);
288 printf ("* Without explicit marks:\n");
289 benchmark (TEST_STRING, niter);
291 printf ("* With explicit marks:\n");
292 benchmark (TEST_STRING_EXPLICIT, niter);
297 /* Editor directions:
298 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent