File indexing completed on 2024-11-10 04:00:28
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt boud @valdyas.org 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_datamanager_benchmark.h" 0008 #include "kis_benchmark_values.h" 0009 0010 #include <simpletest.h> 0011 #include <kis_datamanager.h> 0012 0013 // RGBA 0014 #define PIXEL_SIZE 4 0015 //#define CYCLES 100 0016 0017 void KisDatamanagerBenchmark::initTestCase() 0018 { 0019 // To make sure all the first-time startup costs are done 0020 quint8 * p = new quint8[PIXEL_SIZE]; 0021 memset(p, 0, PIXEL_SIZE); 0022 KisDataManager dm(PIXEL_SIZE, p); 0023 } 0024 0025 void KisDatamanagerBenchmark::benchmarkCreation() 0026 { 0027 // tests the cost of creating a new datamanager 0028 0029 QBENCHMARK { 0030 quint8 * p = new quint8[PIXEL_SIZE]; 0031 memset(p, 255, PIXEL_SIZE); 0032 KisDataManager dm(PIXEL_SIZE, p); 0033 } 0034 } 0035 0036 void KisDatamanagerBenchmark::benchmarkWriteBytes() 0037 { 0038 quint8 *p = new quint8[PIXEL_SIZE]; 0039 memset(p, 0, PIXEL_SIZE); 0040 KisDataManager dm(PIXEL_SIZE, p); 0041 0042 quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT]; 0043 memset(bytes, 128, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT); 0044 0045 QBENCHMARK { 0046 #ifdef CYCLES 0047 for (int i = 0; i < CYCLES; i++){ 0048 dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0049 } 0050 #else 0051 dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0052 #endif 0053 } 0054 0055 delete[] bytes; 0056 } 0057 0058 void KisDatamanagerBenchmark::benchmarkReadBytes() 0059 { 0060 quint8 *p = new quint8[PIXEL_SIZE]; 0061 memset(p, 0, PIXEL_SIZE); 0062 KisDataManager dm(PIXEL_SIZE, p); 0063 0064 quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT]; 0065 memset(bytes, 128, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT); 0066 0067 QBENCHMARK { 0068 dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0069 } 0070 0071 delete[] bytes; 0072 } 0073 0074 0075 void KisDatamanagerBenchmark::benchmarkReadWriteBytes() 0076 { 0077 quint8 *p = new quint8[PIXEL_SIZE]; 0078 memset(p, 0, PIXEL_SIZE); 0079 KisDataManager dm(PIXEL_SIZE, p); 0080 0081 quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT]; 0082 memset(bytes, 120, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT); 0083 0084 dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0085 0086 QBENCHMARK { 0087 #ifdef CYCLES 0088 for (int i = 0; i < 100; i++){ 0089 dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0090 } 0091 #else 0092 dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0093 #endif 0094 } 0095 delete[] bytes; 0096 } 0097 0098 void KisDatamanagerBenchmark::benchmarkReadWriteBytes2() 0099 { 0100 quint8 *p = new quint8[PIXEL_SIZE]; 0101 memset(p, 0, PIXEL_SIZE); 0102 KisDataManager dm(PIXEL_SIZE, p); 0103 0104 KisDataManager dab(PIXEL_SIZE, p); 0105 0106 { 0107 quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT]; 0108 memset(bytes, 120, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT); 0109 0110 dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0111 dab.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0112 delete[] bytes; 0113 } 0114 0115 QBENCHMARK { 0116 int size = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT; 0117 quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT]; 0118 quint8 *bytes2 = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT]; 0119 dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0120 dab.readBytes(bytes2, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0121 quint8 *bytes_it = bytes; 0122 quint8 *bytes2_it = bytes2; 0123 for (int i = 0; i < size; i += PIXEL_SIZE, bytes_it += PIXEL_SIZE, bytes2_it += PIXEL_SIZE) 0124 { 0125 memcpy(bytes_it, bytes2_it, PIXEL_SIZE); 0126 } 0127 dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT); 0128 delete[] bytes; 0129 delete[] bytes2; 0130 } 0131 } 0132 0133 void KisDatamanagerBenchmark::benchmarkExtent() 0134 { 0135 quint8 *p = new quint8[PIXEL_SIZE]; 0136 memset(p, 0, PIXEL_SIZE); 0137 KisDataManager dm(PIXEL_SIZE, p); 0138 quint8 *bytes = new quint8[PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT]; 0139 memset(bytes, 0, PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT); 0140 dm.writeBytes(bytes, 0, 0, NO_TILE_EXACT_BOUNDARY_WIDTH, NO_TILE_EXACT_BOUNDARY_HEIGHT); 0141 QBENCHMARK { 0142 QRect extent = dm.extent(); 0143 Q_UNUSED(extent); 0144 } 0145 } 0146 0147 void KisDatamanagerBenchmark::benchmarkClear() 0148 { 0149 quint8 *p = new quint8[PIXEL_SIZE]; 0150 memset(p, 128, PIXEL_SIZE); 0151 KisDataManager dm(PIXEL_SIZE, p); 0152 quint8 *bytes = new quint8[PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT]; 0153 0154 memset(bytes, 0, PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT); 0155 dm.writeBytes(bytes, 0, 0, NO_TILE_EXACT_BOUNDARY_WIDTH, NO_TILE_EXACT_BOUNDARY_HEIGHT); 0156 0157 // 80% of the image will be cleared 0158 quint32 clearWidth = 0.8 * NO_TILE_EXACT_BOUNDARY_WIDTH; 0159 quint32 clearHeight = 0.8 * NO_TILE_EXACT_BOUNDARY_HEIGHT; 0160 0161 QBENCHMARK { 0162 dm.clear(0, 0, clearWidth, clearHeight, p); 0163 } 0164 0165 } 0166 0167 0168 void KisDatamanagerBenchmark::benchmarkMemCpy() 0169 { 0170 quint64 imgSize = PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT; 0171 quint8 * src = new quint8[imgSize]; 0172 quint8 * dst = new quint8[imgSize]; 0173 memset(src,128, imgSize); 0174 memset(dst,0, imgSize); 0175 QBENCHMARK{ 0176 #ifdef CYCLES 0177 for (int i = 0; i < 100; i++){ 0178 memcpy(dst, src , imgSize); 0179 } 0180 #else 0181 memcpy(dst, src , imgSize); 0182 #endif 0183 } 0184 0185 delete[] src; 0186 delete[] dst; 0187 } 0188 0189 0190 SIMPLE_TEST_MAIN(KisDatamanagerBenchmark)