The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

TestRunner.vala in birdfont-test

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 birdfont-test/TestRunner.vala.
Speed optimizations and benchmarks
1 using BirdFont; 2 using Cairo; 3 4 namespace BirdFont { 5 6 public class TestRunner : NativeWindow, GLib.Object { 7 8 public static void run (string[] args) { 9 if (args.length < 2) { 10 print_usage (args); 11 Process.exit (0); 12 } 13 14 string type = args[1]; 15 16 if (type == "SVG" || type == "BF") { 17 fuzz_test (args); 18 } else if (type == "speed") { 19 speed_test (); 20 } else { 21 print_usage (args); 22 } 23 24 } 25 26 static void print_usage (string[] args) { 27 print ("Usage: " + args[0] + " TEST FILE\n"); 28 print ("TEST parameter can be BF SVG or speed\n"); 29 } 30 31 public static void fuzz_test (string[] arg) { 32 return_if_fail (arg.length == 3); 33 34 string type = arg[1]; 35 string file = arg[2]; 36 37 if (type == "SVG") { 38 File f = File.new_for_path (file); 39 Font font = new Font (); 40 import_svg_file (font, f); 41 } else if (type == "BF") { 42 Font font = new Font (); 43 font.set_font_file (file); 44 font.load (); 45 } 46 47 Process.exit (0); 48 } 49 50 static void speed_test () { 51 Test test_object = new Test.time ("GObject"); 52 53 for (uint i = 0; i < 3000 * 300; i++) { 54 GLib.Object o = new GLib.Object (); 55 } 56 57 test_object.print (); 58 59 Test test_ref = new Test.time ("GObject ref"); 60 61 for (uint i = 0; i < 3000 * 300; i++) { 62 GLib.Object o = new GLib.Object (); 63 64 for (int j = 0; j < 7; j++) { 65 o.ref (); 66 } 67 68 for (int j = 0; j < 7; j++) { 69 o.unref (); 70 } 71 } 72 73 test_ref.print (); 74 75 Test test_edit_point = new Test.time ("EditPoint creation"); 76 77 for (uint i = 0; i < 3000 * 300; i++) { 78 EditPoint ep = new EditPoint (); 79 } 80 81 test_edit_point.print (); 82 83 Test test_path = new Test.time ("Simple path creation"); 84 85 for (uint i = 0; i < 3000 * 300; i++) { 86 Path p = new Path (); 87 } 88 89 test_path.print (); 90 91 Test test_points = new Test.time ("Simple path with points"); 92 93 for (int i = 0; i < 3000; i++) { 94 Path p = new Path (); 95 for (int j = 0; j < 300; j++) { 96 p.add (0, 0); 97 } 98 } 99 100 test_points.print (); 101 102 Test test_cairo = new Test.time ("Simple Cairo"); 103 104 for (int i = 0; i < 3000; i++) { 105 ImageSurface s; 106 Context c; 107 108 s = Screen.create_background_surface (1000, 1000); 109 c = new Context (s); 110 111 for (int j = 0; j < 300; j++) { 112 c.save (); 113 c.rectangle (100, 100, 100, 100); 114 c.fill (); 115 c.restore (); 116 } 117 } 118 119 test_cairo.print (); 120 121 122 Test test_toolbox = new Test.time ("Toolbox"); 123 124 for (int i = 0; i < 30; i++) { 125 ImageSurface s; 126 Context c; 127 128 s = Screen.create_background_surface (1000, 1000); 129 c = new Context (s); 130 MainWindow.get_toolbox ().draw (300, 500, c); 131 } 132 133 test_toolbox.print (); 134 135 Test test_tool_drawing = new Test.time ("Draw Tool"); 136 137 for (int i = 0; i < 30; i++) { 138 ImageSurface s; 139 Context c; 140 Tool tool; 141 142 tool = new Tool (); 143 s = Screen.create_background_surface (100, 100); 144 c = new Context (s); 145 MainWindow.get_toolbox ().draw (300, 500, c); 146 } 147 148 test_tool_drawing.print (); 149 150 Test test_tool = new Test.time ("Create Tool"); 151 152 for (int i = 0; i < 30; i++) { 153 Tool tool; 154 tool = new Tool (); 155 tool.set_tool_visibility (true); 156 } 157 158 test_tool.print (); 159 160 161 Test test_text = new Test.time ("Text"); 162 163 for (int i = 0; i < 30; i++) { 164 ImageSurface s; 165 Context c; 166 167 s = Screen.create_background_surface (100, 100); 168 c = new Context (s); 169 170 Text text = new Text ("This is a test."); 171 text.draw_at_top (c, 0, 0); 172 } 173 174 test_text.print (); 175 } 176 177 public void file_chooser (string title, FileChooser file_chooser_callback, uint flags) { 178 } 179 180 public void update_window_size () { 181 } 182 183 public string get_clipboard_data (){ 184 return ""; 185 } 186 187 public void set_clipboard (string data) { 188 } 189 190 public void set_inkscape_clipboard (string data) { 191 } 192 193 public void set_scrollbar_size (double size) { 194 } 195 196 public void set_scrollbar_position (double position) { 197 } 198 199 public void font_loaded () { 200 } 201 202 public void quit () { 203 Process.exit (0); 204 } 205 206 public bool convert_to_png (string from, string to) { 207 return false; 208 } 209 210 public void export_font () { 211 } 212 213 public void load () { 214 } 215 216 public void save () { 217 } 218 219 public void load_background_image () { 220 } 221 222 public void run_background_thread (Task t) { 223 unowned Thread<void*> bg; 224 225 MenuTab.start_background_thread (); 226 227 try { 228 bg = Thread.create<void*> (t.perform_task, true); 229 } catch (GLib.Error e) { 230 warning (e.message); 231 } 232 } 233 234 public void run_non_blocking_background_thread (Task t) { 235 unowned Thread<void*> bg; 236 237 try { 238 bg = Thread.create<void*> (t.perform_task, true); 239 } catch (GLib.Error e) { 240 warning (e.message); 241 } 242 } 243 244 public void set_clipboard_text (string text) { 245 } 246 247 public string get_clipboard_text () { 248 return ""; 249 } 250 251 public bool can_export () { 252 return true; 253 } 254 255 public void set_cursor (int visible) { 256 } 257 258 public double get_screen_scale () { 259 return 1; 260 } 261 } 262 263 } 264 265 public static int main (string[] arg) { 266 TestRunner runner; 267 MainWindow window; 268 BirdFont.BirdFont birdfont; 269 string[] birdfont_args = new string[1]; 270 271 birdfont_args[0] = arg[0]; 272 birdfont = new BirdFont.BirdFont (); 273 birdfont.init (birdfont_args, null, "birdfont"); 274 275 window = new MainWindow (); 276 runner = new TestRunner (); 277 278 window.set_native (runner); 279 TestRunner.run (arg); 280 281 return 0; 282 } 283