Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: GDAL Core
5 : * Purpose: Test performance of GDADLTranspose2D().
6 : * Author: Even Rouault, <even dot rouault at spatialys.com>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
10 : *
11 : * SPDX-License-Identifier: MIT
12 : ****************************************************************************/
13 :
14 : #include "gdal.h"
15 : #include "cpl_conv.h"
16 :
17 : #include <cstdio>
18 : #include <cstdlib>
19 : #include <ctime>
20 :
21 : #define SIZE (1024 * 1024 + 1) * 100
22 :
23 0 : static void test(const void *pSrc, GDALDataType eSrcType, void *pDst,
24 : GDALDataType eDstType, int W, int H, int reducFactor,
25 : const char *extraMsg = "")
26 : {
27 0 : CPLAssert(W * H <= SIZE);
28 :
29 0 : const int niters =
30 0 : static_cast<int>(4000U * 1000 * 1000 / reducFactor / W / H);
31 0 : const auto start = clock();
32 0 : for (int i = 0; i < niters; ++i)
33 0 : GDALTranspose2D(pSrc, eSrcType, pDst, eDstType, W, H);
34 0 : const auto end = clock();
35 0 : printf("W=%d, H=%d, reducFactor=%d%s: %0.2f sec\n", W, H, reducFactor,
36 0 : extraMsg, (end - start) * reducFactor * 1.0 / CLOCKS_PER_SEC);
37 0 : }
38 :
39 1 : int main(int /* argc */, char * /* argv */[])
40 : {
41 1 : if (strstr(GDALVersionInfo("--version"), "debug build"))
42 : {
43 1 : printf("Skipping testperftranspose as this a debug build!\n");
44 1 : return 0;
45 : }
46 :
47 0 : void *src = CPLCalloc(1, SIZE);
48 0 : void *dst = CPLCalloc(1, SIZE);
49 :
50 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 2, 1);
51 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 3, 1);
52 : #if defined(HAVE_SSSE3_AT_COMPILE_TIME) && defined(DEBUG)
53 : {
54 0 : CPLConfigOptionSetter oSetters("GDAL_USE_SSSE3", "NO", false);
55 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 3, 10,
56 : " (no SSSE3)");
57 : }
58 : #endif
59 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 4, 1);
60 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 5, 1);
61 : #if defined(HAVE_SSSE3_AT_COMPILE_TIME) && defined(DEBUG)
62 : {
63 0 : CPLConfigOptionSetter oSetters("GDAL_USE_SSSE3", "NO", false);
64 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 5, 10,
65 : " (no SSSE3)");
66 : }
67 : #endif
68 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 16 + 1, 10);
69 : #if defined(HAVE_SSSE3_AT_COMPILE_TIME) && defined(DEBUG)
70 : {
71 0 : CPLConfigOptionSetter oSetters("GDAL_USE_SSSE3", "NO", false);
72 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 16 + 1, 10,
73 : " (no SSSE3)");
74 : }
75 : #endif
76 0 : test(src, GDT_Byte, dst, GDT_Byte, 1024 * 1024 + 1, 100, 10);
77 0 : test(src, GDT_Byte, dst, GDT_Byte, 70 * 1024 + 1, 1024 + 1, 10);
78 : #if defined(HAVE_SSSE3_AT_COMPILE_TIME) && defined(DEBUG)
79 : {
80 0 : CPLConfigOptionSetter oSetters("GDAL_USE_SSSE3", "NO", false);
81 0 : test(src, GDT_Byte, dst, GDT_Byte, 70 * 1024 + 1, 1024 + 1, 10,
82 : " (no SSSE3)");
83 : }
84 : #endif
85 0 : test(src, GDT_Byte, dst, GDT_Byte, 7 * 1024 + 1, 10 * 1024 + 1, 10);
86 : #if defined(HAVE_SSSE3_AT_COMPILE_TIME) && defined(DEBUG)
87 : {
88 0 : CPLConfigOptionSetter oSetters("GDAL_USE_SSSE3", "NO", false);
89 0 : test(src, GDT_Byte, dst, GDT_Byte, 7 * 1024 + 1, 10 * 1024 + 1, 10,
90 : " (no SSSE3)");
91 : }
92 : #endif
93 :
94 0 : VSIFree(src);
95 0 : VSIFree(dst);
96 0 : return 0;
97 : }
|