Test: add CPAutosizePerformance test to validate objj_msgSend speed improvements.

This test was written by cacaodev.

Refs #2103.
This commit is contained in:
Alexander Ljungberg
2014-06-22 12:57:11 +01:00
parent fdb079548e
commit 175a455d75
+63
View File
@@ -0,0 +1,63 @@
@import <AppKit/AppKit.j>
@import <Foundation/Foundation.j>
[CPApplication sharedApplication];
@implementation CPAutosizeTest : OJTestCase
{
CPInteger NUMBER_OF_VIEWS;
CPInteger RESIZES_COUNT;
}
- (void)setUp
{
NUMBER_OF_VIEWS = 100;
RESIZES_COUNT = 500;
}
- (void)testAutosizePerf
{
var dur = 0,
masks = [0,1,2,3,4,5,6,7,8];
for (var i = 0; i < 64; i++)
dur += [self _testAutosizePerfWithMask:i];
CPLog.warn(dur + " ms when autosizing " + RESIZES_COUNT + " times a window with " + NUMBER_OF_VIEWS + " views, using masks " + masks);
}
- (CPInteger)_testAutosizePerfWithMask:(CPInteger)aMask
{
var windowRect = CGRectMake(0, 0, 500, 500);
var _autoSizeWindow = [[CPWindow alloc] initWithContentRect:windowRect styleMask:CPResizableWindowMask];
for (var i = 0; i < NUMBER_OF_VIEWS; i++)
{
var x = (i % 10) * 50,
y = FLOOR(i / 10) * 50,
rect = CGRectMake(x, y, 50, 50);
var autosizeView = [[CPView alloc] initWithFrame:rect];
[autosizeView setAutoresizingMask:aMask];
[[_autoSizeWindow contentView] addSubview:autosizeView];
}
[_autoSizeWindow setFrame:CGRectMake(0, 0, 600, 600)];
var start = new Date();
for (var k = 1; k <= RESIZES_COUNT; k++)
{
var size = 600 + k;
[_autoSizeWindow setFrame:CGRectMake(0, 0, size, size)];
}
var total = new Date() - start;
CPLog.warn("AutosizingMask " + aMask + " -setFrame: avg=" + (total/ RESIZES_COUNT) + " ms. Total = " + total + " ms.");
return total;
}
@end