fixes compile
[platform/upstream/libpinyin.git] / tests / timer.h
1 /* 
2  *  libpinyin
3  *  Library to deal with pinyin.
4  *  
5  *  Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
6  *  
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  * 
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21
22 #ifndef TIMER_H
23 #define TIMER_H
24
25 #include <sys/time.h>
26 #include <stdio.h>
27 #include <glib.h>
28
29
30 static guint32 record_time ()
31 {
32     timeval tv;
33     gettimeofday (&tv, NULL);
34     return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
35 }
36
37 static void print_time (guint32 old_time, guint32 times)
38 {
39     timeval tv;
40     gettimeofday (&tv, NULL);
41
42     guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
43
44     printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n" , wasted , times , ((double) wasted)/times , times * 1000000.0/wasted );
45 }
46
47
48 #endif