2 * fribidi-benchmark.c - command line benchmark tool for libfribidi
4 * $Id: fribidi-benchmark.c,v 1.8 2009-04-14 03:49:52 behdad Exp $
6 * $Date: 2009-04-14 03:49:52 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/bin/fribidi-benchmark.c,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
12 * Dov Grobgeld, 1999, 2000
14 * Copyright (C) 2004 Sharif FarsiWeb, Inc
15 * Copyright (C) 2001,2002 Behdad Esfahbod
16 * Copyright (C) 1999,2000 Dov Grobgeld
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with this library, in a file named COPYING; if not, write to the
30 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31 * Boston, MA 02110-1301, USA
33 * For licensing issues, contact <license@farsiweb.info>.
50 # if !STDC_HEADERS && HAVE_MEMORY_H
58 #if HAVE_SYS_TIMES_H+0
59 # include <sys/times.h>
67 #define appname "fribidi_benchmark"
69 #define MAX_STR_LEN 1000
78 fprintf (stderr, "%s: ", appname);
80 fprintf (stderr, fmt, arg);
81 fprintf (stderr, "Try `%s --help' for more information.\n", appname);
86 "a THE QUICK -123,456 (FOX JUMPS ) DOG the quick !1@7#4&5^ over the dog " \
87 "123,456 OVER THE 5%+ 4.0 LAZY"
88 #define TEST_STRING_EXPLICIT \
89 "this is _LJUST_o a _lsimple _Rte%ST_o th_oat HAS A _LPDF missing" \
90 "AnD hOw_L AbOuT, 123,987 tHiS_o a GO_oOD - _L_oTE_oST. " \
91 "here_L is_o_o_o _R a good one_o And _r 123,987_LT_oHE_R next_o oNE:" \
92 "_R_r and the last _LONE_o IS THE _rbest _lONE and" \
93 "a _L_L_L_LL_L_L_L_L_L_L_L_L_Rbug_o_o_o_o_o_o" \
94 "_R_r and the last _LONE_o IS THE _rbest _lONE and" \
95 "A REAL BIG_l_o BUG! _L _l_r_R_L_laslaj siw_o_Rlkj sslk" \
96 "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" \
97 "here_L is_o_o_o _R ab one_o _r 123,987_LT_oHE_R t_o oNE:" \
105 ("Usage: " appname " [OPTION]...\n"
106 "A program for benchmarking the speed of the " FRIBIDI_NAME
108 " -h, --help Display this information and exit\n"
109 " -V, --version Display version information and exit\n"
110 " -n, --niter N Number of iterations. Default is %d.\n"
111 "\nReport bugs online at\n<" FRIBIDI_BUGREPORT ">.\n", NUM_ITER);
120 printf (appname " %s", fribidi_version_info);
130 FILETIME creationTime, exitTime, kernelTime, userTime;
131 HANDLE currentProcess = GetCurrentProcess();
132 if (GetProcessTimes(currentProcess, &creationTime, &exitTime, &kernelTime, &userTime))
134 unsigned __int64 myTime = userTime.dwHighDateTime;
135 myTime = (myTime << 32) | userTime.dwLowDateTime;
136 return 1e-7 * myTime;
141 #if HAVE_SYS_TIMES_H+0
144 return 0.01 * tb.tms_utime;
146 #warning Please fill in here to use other functions for determining time.
159 FriBidiChar us[MAX_STR_LEN], out_us[MAX_STR_LEN];
160 FriBidiStrIndex positionLtoV[MAX_STR_LEN], positionVtoL[MAX_STR_LEN];
161 FriBidiLevel embedding_list[MAX_STR_LEN];
168 for (i = 0, j = 0; i < len; i++)
174 us[j++] = FRIBIDI_CHAR_LRM;
177 us[j++] = FRIBIDI_CHAR_RLM;
180 us[j++] = FRIBIDI_CHAR_LRE;
183 us[j++] = FRIBIDI_CHAR_RLE;
186 us[j++] = FRIBIDI_CHAR_LRO;
189 us[j++] = FRIBIDI_CHAR_RLO;
192 us[j++] = FRIBIDI_CHAR_PDF;
204 if (us[j] >= 'A' && us[j] <= 'F')
205 us[j] += FRIBIDI_CHAR_ARABIC_ALEF - 'A';
206 else if (us[j] >= 'G' && us[j] <= 'Z')
207 us[j] += FRIBIDI_CHAR_HEBREW_ALEF - 'G';
208 else if (us[j] >= '6' && us[j] <= '9')
209 us[j] += FRIBIDI_CHAR_ARABIC_ZERO - '0';
217 for (i = 0; i < niter; i++)
219 /* Create a bidi string */
220 base = FRIBIDI_PAR_ON;
221 if (!fribidi_log2vis (us, len, &base,
223 out_us, positionVtoL, positionLtoV,
226 ("something failed in fribidi_log2vis.\n"
227 "perhaps memory allocation failure.", NULL);
234 printf ("Length = %d\n", len);
235 printf ("Iterations = %d\n", niter);
236 printf ("%d len*iterations in %f seconds\n", len * niter, time1 - time0);
237 printf ("= %.0f kilo.length.iterations/second\n",
238 1.0 * len * niter / 1000 / (time1 - time0));
249 int niter = NUM_ITER;
251 /* Parse the command line */
255 int option_index = 0, c;
256 static struct option long_options[] = {
258 {"version", 0, 0, 'V'},
259 {"niter", 0, 0, 'n'},
263 c = getopt_long (argc, argv, "hVn:", long_options, &option_index);
278 niter = atoi (optarg);
280 die2 ("invalid number of iterations `%s'\n", optarg);
291 printf ("* Without explicit marks:\n");
292 benchmark (TEST_STRING, niter);
294 printf ("* With explicit marks:\n");
295 benchmark (TEST_STRING_EXPLICIT, niter);
300 /* Editor directions:
301 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent