-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathtestperfcopywords.cpp
101 lines (83 loc) · 3.17 KB
/
testperfcopywords.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
* $Id$
*
* Project: GDAL Core
* Purpose: Test performance of GDALCopyWords().
* Author: Even Rouault, <even dot rouault at spatialys.com>
*
******************************************************************************
* Copyright (c) 2009-2010, Even Rouault <even dot rouault at spatialys.com>
*
* SPDX-License-Identifier: MIT
****************************************************************************/
#include "gdal.h"
#include "cpl_conv.h"
#include <cstdio>
#include <cstdlib>
#include <ctime>
int main(int /* argc */, char * /* argv */[])
{
void *in = calloc(1, 256 * 256 * 16);
void *out = malloc(256 * 256 * 16);
int i;
int intype, outtype;
clock_t start, end;
for (intype = GDT_Byte; intype < GDT_TypeCount; intype++)
{
for (outtype = GDT_Byte; outtype < GDT_TypeCount; outtype++)
{
start = clock();
for (i = 0; i < 1000; i++)
GDALCopyWords(in, (GDALDataType)intype, 16, out,
(GDALDataType)outtype, 16, 256 * 256);
end = clock();
printf("%s -> %s : %.2f s\n",
GDALGetDataTypeName((GDALDataType)intype),
GDALGetDataTypeName((GDALDataType)outtype),
(end - start) * 1.0 / CLOCKS_PER_SEC);
start = clock();
for (i = 0; i < 1000; i++)
GDALCopyWords(in, (GDALDataType)intype,
GDALGetDataTypeSize((GDALDataType)intype) / 8,
out, (GDALDataType)outtype,
GDALGetDataTypeSize((GDALDataType)outtype) / 8,
256 * 256);
end = clock();
printf("%s -> %s (packed) : %.2f s\n",
GDALGetDataTypeName((GDALDataType)intype),
GDALGetDataTypeName((GDALDataType)outtype),
(end - start) * 1.0 / CLOCKS_PER_SEC);
}
}
for (int k = 0; k < 2; k++)
{
if (k == 1)
{
printf("Disabling SSSE3\n");
CPLSetConfigOption("GDAL_USE_SSSE3", "NO");
}
// 2 byte stride --> packed byte
start = clock();
for (i = 0; i < 100000; i++)
GDALCopyWords(in, GDT_Byte, 2, out, GDT_Byte, 1, 256 * 256);
end = clock();
printf("2-byte stride Byte ->packed Byte : %.2f\n",
(end - start) * 1.0 / CLOCKS_PER_SEC);
// 3 byte stride --> packed byte
start = clock();
for (i = 0; i < 100000; i++)
GDALCopyWords(in, GDT_Byte, 3, out, GDT_Byte, 1, 256 * 256);
end = clock();
printf("3-byte stride Byte ->packed Byte : %.2f\n",
(end - start) * 1.0 / CLOCKS_PER_SEC);
// 4 byte stride --> packed byte
start = clock();
for (i = 0; i < 100000; i++)
GDALCopyWords(in, GDT_Byte, 4, out, GDT_Byte, 1, 256 * 256);
end = clock();
printf("4-byte stride Byte ->packed Byte : %.2f\n",
(end - start) * 1.0 / CLOCKS_PER_SEC);
}
CPLSetConfigOption("GDAL_USE_SSSE3", nullptr);
return 0;
}