.
1 /*
2 Copyright (C) 2012, 2014 Johan Mattsson
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 3 of the
7 License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful, but
10 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
15 namespace BirdFont {
16
17 public class Test : Object {
18 public Callback callback;
19 public string name;
20 double time_stamp;
21 bool benchmark = false;
22
23 public Test.time (string name) {
24 this.name = name;
25 benchmark = true;
26 timer_start ();
27 }
28
29 public Test (Callback callback, string name, bool benchmark = false) {
30 this.callback = callback;
31 this.name = name;
32 this.time_stamp = 0;
33 this.benchmark = benchmark;
34 }
35
36 public void timer_start () {
37 time_stamp = GLib.get_real_time ();
38 }
39
40 public double get_time () {
41 double stop_time = GLib.get_real_time ();
42
43 if (time_stamp == 0) {
44 return 0;
45 }
46
47 return (stop_time - time_stamp) / 1000000.0;
48 }
49
50 public bool is_benchmark () {
51 return benchmark;
52 }
53
54 public void print () {
55 stdout.printf (get_test_time ());
56 }
57
58 public string get_test_time () {
59 double stop_time = GLib.get_real_time ();
60
61 if (time_stamp == 0) {
62 return "";
63 }
64
65 return @"$name $((stop_time - time_stamp) / 1000000.0)s\n";
66 }
67 }
68
69 }
70