Relocate current benchmark to /demos/benchmarks/rectangles
This commit is contained in:
parent
c713719326
commit
853f2cba98
@ -16,6 +16,7 @@ CHANGE: STM32LTDC driver: Rename ALLOW_2ND_LAYER to STM32LTDC_USE_LAYER2.
|
|||||||
CHANGE: STM32LTDC driver: Rename LTDC_DMA_CACHE_FLUSH to STM32LTDC_DMA_CACHE_FLUSH.
|
CHANGE: STM32LTDC driver: Rename LTDC_DMA_CACHE_FLUSH to STM32LTDC_DMA_CACHE_FLUSH.
|
||||||
CHANGE: STM32LTDC driver: Rename GDISP_LTDC_USE_RGB565 to STM32LTDC_USE_RGB565.
|
CHANGE: STM32LTDC driver: Rename GDISP_LTDC_USE_RGB565 to STM32LTDC_USE_RGB565.
|
||||||
FEATURE: STM32LTDC driver: Support double buffering. This introduces STM32LTDC_USE_DOUBLEBUFFERING.
|
FEATURE: STM32LTDC driver: Support double buffering. This introduces STM32LTDC_USE_DOUBLEBUFFERING.
|
||||||
|
FIX: Improve /demos/benchmarks/rectangles
|
||||||
|
|
||||||
|
|
||||||
*** Release 2.9 ***
|
*** Release 2.9 ***
|
||||||
|
@ -1,108 +1,108 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2012 - 2021, Joel Bodenmann aka Tectu <joel@ugfx.io>
|
* Copyright (c) 2012 - 2021, Joel Bodenmann aka Tectu <joel@ugfx.io>
|
||||||
* Copyright (c) 2012 - 2021, Andrew Hannam aka inmarket <inmarket@ugfx.io>
|
* Copyright (c) 2012 - 2021, Andrew Hannam aka inmarket <inmarket@ugfx.io>
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the <organization> nor the
|
* * Neither the name of the <organization> nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
#define RESULT_STR_LENGTH 32
|
#define RESULT_STR_LENGTH 32
|
||||||
|
|
||||||
void benchmark(void)
|
void benchmark(void)
|
||||||
{
|
{
|
||||||
gCoord height, width, rx, ry, rcx, rcy;
|
gCoord height, width, rx, ry, rcx, rcy;
|
||||||
gColor random_color;
|
gColor random_color;
|
||||||
gCoord fontHeight;
|
gCoord fontHeight;
|
||||||
gFont font;
|
gFont font;
|
||||||
|
|
||||||
// Prepare resources
|
// Prepare resources
|
||||||
width = gdispGetWidth();
|
width = gdispGetWidth();
|
||||||
height = gdispGetHeight();
|
height = gdispGetHeight();
|
||||||
font = gdispOpenFont("*");
|
font = gdispOpenFont("*");
|
||||||
fontHeight = gdispGetFontMetric(font, gFontHeight);
|
fontHeight = gdispGetFontMetric(font, gFontHeight);
|
||||||
|
|
||||||
// Show intro message
|
// Show intro message
|
||||||
gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter);
|
gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter);
|
||||||
gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, GFX_WHITE, gJustifyCenter);
|
gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, GFX_WHITE, gJustifyCenter);
|
||||||
gfxSleepMilliseconds(3000);
|
gfxSleepMilliseconds(3000);
|
||||||
|
|
||||||
// Seed RNG
|
// Seed RNG
|
||||||
srand(0);
|
srand(0);
|
||||||
|
|
||||||
// Render rectangles and count ticks & pixels
|
// Render rectangles and count ticks & pixels
|
||||||
gU64 pixels = 0;
|
gU64 pixels = 0;
|
||||||
const gTicks ticksStart = gfxSystemTicks();
|
const gTicks ticksStart = gfxSystemTicks();
|
||||||
for (gU32 i = 0; i < 5000; i++) {
|
for (gU32 i = 0; i < 5000; i++) {
|
||||||
random_color = (rand() % 65535);
|
random_color = (rand() % 65535);
|
||||||
rx = (rand() % (width-10));
|
rx = (rand() % (width-10));
|
||||||
ry = (rand() % (height-10));
|
ry = (rand() % (height-10));
|
||||||
rcx = (rand() % ((width-rx)-10))+10;
|
rcx = (rand() % ((width-rx)-10))+10;
|
||||||
rcy = (rand() % ((height-ry)-10))+10;
|
rcy = (rand() % ((height-ry)-10))+10;
|
||||||
|
|
||||||
gdispFillArea(rx, ry, rcx, rcy, random_color);
|
gdispFillArea(rx, ry, rcx, rcy, random_color);
|
||||||
pixels += (rcx+1)*(rcy+1);
|
pixels += (rcx+1)*(rcy+1);
|
||||||
}
|
}
|
||||||
const gTicks ticksEnd = gfxSystemTicks();
|
const gTicks ticksEnd = gfxSystemTicks();
|
||||||
|
|
||||||
// Calculate result
|
// Calculate result
|
||||||
char str_ticks[RESULT_STR_LENGTH];
|
char str_ticks[RESULT_STR_LENGTH];
|
||||||
char str_seconds[RESULT_STR_LENGTH];
|
char str_seconds[RESULT_STR_LENGTH];
|
||||||
char str_pps[RESULT_STR_LENGTH];
|
char str_pps[RESULT_STR_LENGTH];
|
||||||
{
|
{
|
||||||
// Figure out how many ticks are 1 second
|
// Figure out how many ticks are 1 second
|
||||||
const gTicks ticksPerSecond = gfxMillisecondsToTicks(1000);
|
const gTicks ticksPerSecond = gfxMillisecondsToTicks(1000);
|
||||||
|
|
||||||
const gTicks ticksElapsed = ticksEnd - ticksStart;
|
const gTicks ticksElapsed = ticksEnd - ticksStart;
|
||||||
const float secondsElapsed = (float)ticksElapsed / (float)ticksPerSecond;
|
const float secondsElapsed = (float)ticksElapsed / (float)ticksPerSecond;
|
||||||
gU32 pps = (float)pixels / secondsElapsed;
|
gU32 pps = (float)pixels / secondsElapsed;
|
||||||
|
|
||||||
// Produce strings
|
// Produce strings
|
||||||
memset(str_ticks, 0, RESULT_STR_LENGTH);
|
memset(str_ticks, 0, RESULT_STR_LENGTH);
|
||||||
memset(str_seconds, 0, RESULT_STR_LENGTH);
|
memset(str_seconds, 0, RESULT_STR_LENGTH);
|
||||||
memset(str_pps, 0, RESULT_STR_LENGTH);
|
memset(str_pps, 0, RESULT_STR_LENGTH);
|
||||||
snprintg(str_ticks, RESULT_STR_LENGTH, "%d ticks", ticksElapsed);
|
snprintg(str_ticks, RESULT_STR_LENGTH, "%d ticks", ticksElapsed);
|
||||||
snprintg(str_pps, RESULT_STR_LENGTH, "%d pixels/s", pps);
|
snprintg(str_pps, RESULT_STR_LENGTH, "%d pixels/s", pps);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show result
|
// Show result
|
||||||
gdispClear(GFX_BLACK);
|
gdispClear(GFX_BLACK);
|
||||||
gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter);
|
gdispDrawStringBox(0, 0, width, 30, "uGFX - Benchmark", font, GFX_WHITE, gJustifyCenter);
|
||||||
gdispDrawStringBox(0, height/2+0*(fontHeight+10), width, 30, str_ticks, font, GFX_WHITE, gJustifyCenter);
|
gdispDrawStringBox(0, height/2+0*(fontHeight+10), width, 30, str_ticks, font, GFX_WHITE, gJustifyCenter);
|
||||||
gdispDrawStringBox(0, height/2+1*(fontHeight+10), width, 30, str_pps, font, GFX_WHITE, gJustifyCenter);
|
gdispDrawStringBox(0, height/2+1*(fontHeight+10), width, 30, str_pps, font, GFX_WHITE, gJustifyCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
gfxInit();
|
gfxInit();
|
||||||
|
|
||||||
benchmark();
|
benchmark();
|
||||||
|
|
||||||
while (gTrue)
|
while (gTrue)
|
||||||
gfxSleepMilliseconds(500);
|
gfxSleepMilliseconds(500);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user