Created
November 14, 2011 11:56
-
-
Save tbuschto/1363799 to your computer and use it in GitHub Desktop.
Simple RAP performance test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* Copyright (c) 2011 EclipseSource and others. All rights reserved. | |
******************************************************************************/ | |
import org.eclipse.rwt.internal.widgets.JSExecutor; | |
import org.eclipse.rwt.lifecycle.IEntryPoint; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.widgets.Button; | |
import org.eclipse.swt.widgets.Canvas; | |
import org.eclipse.swt.widgets.Display; | |
import org.eclipse.swt.widgets.Shell; | |
import org.eclipse.swt.events.PaintEvent; | |
import org.eclipse.swt.events.PaintListener; | |
import org.eclipse.swt.events.SelectionAdapter; | |
import org.eclipse.swt.events.SelectionEvent; | |
import org.eclipse.swt.events.SelectionListener; | |
import org.eclipse.swt.graphics.Color; | |
import org.eclipse.swt.graphics.RGB; | |
import org.eclipse.swt.layout.*; | |
public class SpeedTest implements IEntryPoint { | |
public final static void activate() { | |
JSExecutor.executeJS( | |
"( function() {" | |
+ " var measureWrap = function( context, field ) {" | |
+ " var orgFunc = context[ field ];" | |
+ " context[ field ] = function() {" | |
+ " var start = new Date();" | |
+ " orgFunc.apply( context, [ arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] ] );" | |
+ " var stop = new Date();" | |
+ " var diff = stop.getTime() - start.getTime();" | |
+ " if( diff > 10 ) {" | |
+ " console.log( field + ': ' + diff );" | |
+ " }" | |
+ " };" | |
+ " };" | |
+ " measureWrap( org.eclipse.swt.Request.getInstance(), '_handleCompleted' );" | |
+ " measureWrap( qx.ui.core.Widget, 'flushGlobalQueues' );" | |
+ "} )();" | |
); | |
} | |
@Override | |
public int createUI() { | |
final Display display = new Display(); | |
final Shell shell = new Shell( display ); | |
shell.setLayout( new GridLayout() ); | |
Button b1 = new Button( shell, SWT.PUSH ); | |
b1.setText( "canvasTest" ); | |
b1.addSelectionListener( new SelectionAdapter() { | |
public void widgetSelected( SelectionEvent e ) { | |
Shell canvasShell = new Shell( display ); | |
canvasShell.setLayout( new FillLayout() ); | |
canvasShell.setSize( 600, 600 ); | |
Canvas c = new Canvas( canvasShell, SWT.NONE ); | |
c.addPaintListener( new PaintListener() { | |
public void paintControl( PaintEvent event ) { | |
for( int i = 0; i < 500; i++ ) { | |
int systemColor = i % 2 == 0 ? SWT.COLOR_BLACK : SWT.COLOR_WHITE; | |
event.gc.setForeground( display.getSystemColor( systemColor ) ); | |
event.gc.drawLine( 0, i, 400, i ); | |
} | |
for( int i = 0; i < 500; i++ ) { | |
int systemColor = i % 2 == 0 ? SWT.COLOR_BLACK : SWT.COLOR_WHITE; | |
event.gc.setForeground( display.getSystemColor( systemColor ) ); | |
event.gc.drawLine( i, 0, i, 400 ); | |
} | |
} | |
} ); | |
canvasShell.open(); | |
} | |
} ); | |
Button b2 = new Button( shell, SWT.PUSH ); | |
b2.setText( "buttonTest" ); | |
b2.addSelectionListener( new SelectionAdapter() { | |
public void widgetSelected( SelectionEvent e ) { | |
Shell buttonShell = new Shell( display ); | |
buttonShell.setLayout( new GridLayout( 10, true ) ); | |
buttonShell.setSize( 600, 600 ); | |
for( int i = 0; i < 200; i++ ) { | |
Button b = new Button( buttonShell, SWT.PUSH ); | |
b.setText( String.valueOf( i ) ); | |
} | |
buttonShell.open(); | |
} | |
} ); | |
shell.open(); | |
activate(); | |
while (!display.isDisposed()) { | |
if (!display.readAndDispatch()) display.sleep(); | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment