/* * ******************************************************************************** * * Ueeze - User Interface Easy as every one should be! * * * Copyright (C) 1998-1999 Wabasoft * * * Copyright (C) 2000-2012 SuperWaba Ltda. * * * Copyright (C) 2017-2018 S&P Computersysteme GmbH * * * All Rights Reserved * * * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * * FITNESS FOR A PARTICULAR PURPOSE. * * * * * * This file is covered by the GNU LESSER GENERAL PUBLIC LICENSE VERSION 3.0 * * * A copy of this license can be downloaded here: * * * http://www.gnu.org/licenses/lgpl-3.0.txt * * * * * ******************************************************************************** */ package samples.showcase; import ueeze.ui.event.*; import ueeze.ui.base.*; import ueeze.ui.geom.*; import ueeze.util.*; /** * Created by Guilherme on 02/01/2018. */ public class Bench { public Bench() { } class TestClass { public int field1 = 70; public int field2 = 80; public int method1(int value) { return (field1 % value) + field2 / 2; } public int method2(int value) { return (field2 % value) + field1 / 2; } } ////////// random - by Sean Luke ///////////////// protected static int lastSeed = 234123; /** bits should be <= 31. used by the random method */ protected static int next(final int bits) { int IA = 16807; int IM = 2147483647; int IQ = 127773; int IR = 2836; int k = lastSeed / IQ; lastSeed = IA * (lastSeed - k * IQ) - IR * k; if (lastSeed < 0) lastSeed += IM; return lastSeed >> (31 - bits); } /** * This is a simple Linear Congruential Generator which produces random * numbers in the range [0,2^31), derived from ran0 in Numerical Recipies. * Note that ran0 isn't wonderfully random -- there are much better * generators out there -- but it'll do the job, and it's fast and has low * memory consumption. * * @param _seed * if > 0, sets the seed, if = 0, uses the last seed. You should * call Math.random(RuntimeUtils.ellapsedMillis()); * @return a positive 32 bits random int */ public static int rrandom(int _seed) { if (_seed != 0) // use the last rand if seed == 0. { // strip out the minus-sign if any lastSeed = (_seed << 1) >>> 1; } int val = next(31); if (val < 0) val = -val; return val; } boolean run; String loop, field, method, array, string; Rectangle rect = new Rectangle(); public void paint(Graphics g) { String s; int start, end; // paint tests g.fill(rect.set(0, 0, 160, 160).color(Color.WHITE)); rect.color(Color.BLACK); start = Device.ellapsedMillis(); for (int i = 0; i < 8000; i++) { switch (rrandom(0) % 2) { case 0: g.draw(rect.set(rrandom(0) % 150, rrandom(0) % 150, 10, 10)); break; case 1: g.drawLine(rrandom(0) % 150, rrandom(0) % 150, rrandom(0) % 150, rrandom(0) % 150, Color.BLACK); break; } } end = Device.ellapsedMillis(); s = "Graphics: " + (end - start) + " ms"; if (!run) { run = true; runTests(); } int y = 170; int fh = g.font.height(); g.drawText(s, 10,y, Color.BLACK); y += fh; g.drawText(loop, 10,y, Color.BLACK); y += fh; g.drawText(field, 10,y, Color.BLACK); y += fh; g.drawText(method, 10,y, Color.BLACK); y += fh; g.drawText(array, 10,y, Color.BLACK); y += fh; g.drawText(string, 10,y, Color.BLACK); } public void runTests() { int start, end, value; // loop test start = Device.ellapsedMillis(); value = 100; for (int i = 0; i < 10000000; i++) { value = value / 7; if (value == 0) value = i / 3; } end = Device.ellapsedMillis(); loop = "Loop: " + (end - start) + " ms"; // field test TestClass test = new TestClass(); start = Device.ellapsedMillis(); value = 100; for (int i = 0; i < 1000000; i++) { value += test.field1 + test.field2; test.field1 = i; test.field2 = i; value = value % 100; } end = Device.ellapsedMillis(); field = "Field: " + (end - start) + " ms"; start = Device.ellapsedMillis(); value = 100; for (int i = 1; i < 1000000; i++) { value = test.method1(i); value += test.method2(i); value = value % 100; } end = Device.ellapsedMillis(); method = "Method: " + (end - start) + " ms"; // array test byte a[] = new byte[30]; start = Device.ellapsedMillis(); for (int i = 0; i < 1000000; i++) for (int j = 0; j < 30; j++) a[j] = (byte) (a[j] + (j / 2)); end = Device.ellapsedMillis(); array = "Array: " + (end - start) + " ms"; // string test String strings[] = new String[3000]; for (int i = 0; i < strings.length; i++) strings[i] = "Num" + i; start = Device.ellapsedMillis(); for (int i = 0; i < 10000; i++) { String z = "All"; for (int j = 0; j < 30; j++) z += strings[j]; } end = Device.ellapsedMillis(); string = "String: " + (end - start) + " ms"; } public void processEvent(Event e) { if (e.type == TouchEvent.TOUCH_DOWN) App.exit(0); } }