MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / timingTest

Method timingTest

src/org/opensourcephysics/display/GUIUtils.java:383–403  ·  view source on GitHub ↗

Test the time to render a drawable component. @param drawable

(Drawable drawable)

Source from the content-addressed store, hash-verified

381 * @param drawable
382 */
383 public static void timingTest(Drawable drawable) {
384 DrawingPanel dp = new DrawingPanel();
385 DrawingFrame df = new DrawingFrame(dp);
386 df.setVisible(true);
387 dp.addDrawable(drawable);
388 dp.scale();
389 dp.setPixelScale();
390 Graphics g2 = dp.getGraphics();
391 if (g2 == null) {
392 return;
393 }
394 long startTime = System.currentTimeMillis();
395 drawable.draw(dp, g2); // first drawing often takes longer because of initialization
396 System.out.print("first drawing=" + (System.currentTimeMillis() - startTime)); //$NON-NLS-1$
397 startTime = System.currentTimeMillis(); // reset the time
398 for (int i = 0; i < 5; i++) {
399 drawable.draw(dp, g2);
400 }
401 System.out.println(" avg time/drawing=" + ((System.currentTimeMillis() - startTime) / 5)); //$NON-NLS-1$
402 g2.dispose();
403 }
404
405 /**
406 * Saves the contents of the specified component in the given file format. Note

Callers

nothing calls this directly

Calls 8

addDrawableMethod · 0.95
scaleMethod · 0.95
setPixelScaleMethod · 0.95
setVisibleMethod · 0.65
drawMethod · 0.65
printMethod · 0.65
printlnMethod · 0.65
disposeMethod · 0.65

Tested by

no test coverage detected