|
@@ -9,7 +9,7 @@
|
9
|
9
|
#include <DK.h>
|
10
|
10
|
|
11
|
11
|
|
12
|
|
-#define MAX_SIZE 50000000ULL
|
|
12
|
+#define MAX_SIZE 80000000ULL
|
13
|
13
|
|
14
|
14
|
struct Value64
|
15
|
15
|
{
|
|
@@ -60,9 +60,11 @@ void DoTest(bool dkFirst, Rand&& r)
|
60
|
60
|
|
61
|
61
|
DKThread::Sleep(0.2);
|
62
|
62
|
|
63
|
|
- auto testSTL = [](T* val, size_t len)->DKHashResultSHA1
|
|
63
|
+ using ResultTuple = DKTuple<DKHashResultSHA1, double>;
|
|
64
|
+
|
|
65
|
+ auto testSTL = [](T* val, size_t len)->ResultTuple
|
64
|
66
|
{
|
65
|
|
- DKLogI("Sorting by std::sort...");
|
|
67
|
+ DKLog("Sorting by std::sort...");
|
66
|
68
|
DKTimer timer;
|
67
|
69
|
timer.Reset();
|
68
|
70
|
std::sort(val, val + len, [](const auto& lhs, const auto& rhs)->bool
|
|
@@ -73,12 +75,12 @@ void DoTest(bool dkFirst, Rand&& r)
|
73
|
75
|
DKLogW("std::sort: %f", e1);
|
74
|
76
|
auto hash = DKHashSHA1(val, sizeof(T) * len);
|
75
|
77
|
DKLog("std::sort hash: %ls", (const wchar_t*)hash.String());
|
76
|
|
- return hash;
|
|
78
|
+ return ResultTuple::Make(hash, e1);
|
77
|
79
|
};
|
78
|
80
|
|
79
|
|
- auto testDK = [](T* val, size_t len)->DKHashResultSHA1
|
|
81
|
+ auto testDK = [](T* val, size_t len)->ResultTuple
|
80
|
82
|
{
|
81
|
|
- DKLogI("Sorting by DKStaticArray::Sort...");
|
|
83
|
+ DKLog("Sorting by DKStaticArray::Sort...");
|
82
|
84
|
DKStaticArray<T> tmp(val, len);
|
83
|
85
|
DKTimer timer;
|
84
|
86
|
timer.Reset();
|
|
@@ -86,24 +88,34 @@ void DoTest(bool dkFirst, Rand&& r)
|
86
|
88
|
{
|
87
|
89
|
return lhs < rhs;
|
88
|
90
|
});
|
89
|
|
- double e2 = timer.Elapsed();
|
90
|
|
- DKLogW("DKStaticArray::Sort: %f (SwapMethod:%d)", e2, tmp.SwapMethod);
|
|
91
|
+ double e1 = timer.Elapsed();
|
|
92
|
+ DKLogW("DKStaticArray::Sort: %f (SwapMethod:%d)", e1, tmp.SwapMethod);
|
91
|
93
|
auto hash = DKHashSHA1(val, sizeof(T) * len);
|
92
|
94
|
DKLog("DKStaticArray::Sort hash: %ls", (const wchar_t*)hash.String());
|
93
|
|
- return hash;
|
|
95
|
+ return ResultTuple::Make(hash, e1);
|
94
|
96
|
};
|
95
|
97
|
|
96
|
98
|
if (dkFirst)
|
97
|
99
|
{
|
98
|
|
- auto hash1 = testDK(val1, MAX_SIZE);
|
99
|
|
- auto hash2 = testSTL(val2, MAX_SIZE);
|
100
|
|
- DKLog("Hash compare: %d", hash1.Compare(hash2));
|
|
100
|
+ auto result1 = testDK(val1, MAX_SIZE);
|
|
101
|
+ auto result2 = testSTL(val2, MAX_SIZE);
|
|
102
|
+ if (result1.Value<0>().Compare(result2.Value<0>()))
|
|
103
|
+ DKLogE("Hash Compare: %d (ERROR)", result1.Value<0>().Compare(result2.Value<0>()));
|
|
104
|
+ else
|
|
105
|
+ DKLogI("Hash compare: %d (time: %f)",
|
|
106
|
+ result1.Value<0>().Compare(result2.Value<0>()),
|
|
107
|
+ result1.Value<1>() - result2.Value<1>());
|
101
|
108
|
}
|
102
|
109
|
else
|
103
|
110
|
{
|
104
|
|
- auto hash1 = testSTL(val1, MAX_SIZE);
|
105
|
|
- auto hash2 = testDK(val2, MAX_SIZE);
|
106
|
|
- DKLog("Hash compare: %d", hash1.Compare(hash2));
|
|
111
|
+ auto result1 = testDK(val1, MAX_SIZE);
|
|
112
|
+ auto result2 = testSTL(val2, MAX_SIZE);
|
|
113
|
+ if (result1.Value<0>().Compare(result2.Value<0>()))
|
|
114
|
+ DKLogE("Hash Compare: %d (ERROR)", result1.Value<0>().Compare(result2.Value<0>()));
|
|
115
|
+ else
|
|
116
|
+ DKLogI("Hash compare: %d (time: %f)",
|
|
117
|
+ result1.Value<0>().Compare(result2.Value<0>()),
|
|
118
|
+ result1.Value<1>() - result2.Value<1>());
|
107
|
119
|
}
|
108
|
120
|
|
109
|
121
|
delete[] val1;
|
|
@@ -125,13 +137,13 @@ int main(int argc, const char * argv[])
|
125
|
137
|
|
126
|
138
|
DoTest<Value64>(true, []()->Value64
|
127
|
139
|
{
|
128
|
|
- Value64 val;
|
|
140
|
+ Value64 val = { 0 };
|
129
|
141
|
val.num = DKRandom();
|
130
|
142
|
return val;
|
131
|
143
|
});
|
132
|
144
|
DoTest<Value16>(true, []()->Value16
|
133
|
145
|
{
|
134
|
|
- Value16 val;
|
|
146
|
+ Value16 val = { 0 };
|
135
|
147
|
val.num = DKRandom();
|
136
|
148
|
return val;
|
137
|
149
|
});
|