The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Test.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/Test.vala.
Write benchmark time to string
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 return (stop_time - time_stamp) / 1000000.0; 43 } 44 45 public bool is_benchmark () { 46 return benchmark; 47 } 48 49 public static void print_time (string mess, double start_time) { 50 double stop_time = GLib.get_real_time (); 51 stdout.printf (@"$mess $((stop_time - start_time) / 1000000.0)s\n"); 52 } 53 54 public void print () { 55 print_time (name, time_stamp); 56 } 57 } 58 59 } 60