Browse Source

데이터 유형 추가.

Hongtae Kim 6 years ago
parent
commit
25ab01b48c
1 changed files with 152 additions and 39 deletions
  1. 152
    39
      WETSort/WETSort.cpp

+ 152
- 39
WETSort/WETSort.cpp View File

@@ -22,8 +22,8 @@
22 22
 std::string sha1(const void* p, size_t s);
23 23
 
24 24
 const size_t testLength[] = {
25
-	1ULL << 21,
26
-	1ULL << 27,
25
+	1ULL << 24,
26
+	1ULL << 29,
27 27
 #ifndef _DEBUG
28 28
 	1ULL << 31,
29 29
 	1ULL << 33
@@ -65,6 +65,17 @@ struct TestResult
65 65
 	std::string hash;
66 66
 };
67 67
 
68
+enum GenerateDataTypes
69
+{
70
+	GenUniform32,
71
+	GenUniform16,
72
+	GenUniform16Xor,
73
+	GenUniform8,
74
+	GenUniform8Xor,
75
+	GenNormal64,
76
+	GenNormal32,
77
+};
78
+
68 79
 #pragma pack(push, 1)
69 80
 template <size_t s>
70 81
 struct Element
@@ -72,15 +83,11 @@ struct Element
72 83
 	int8_t buffer[s];
73 84
 	bool operator < (const Element& other) const
74 85
 	{
75
-		const int8_t* p0 = buffer;
76
-		const int8_t* p1 = other.buffer;
77 86
 		for (size_t i = 0; i < s; ++i)
78 87
 		{
79
-			int n = p0[0] - p1[0];
88
+			int n = int(buffer[i]) - int(other.buffer[i]);
80 89
 			if (n)
81 90
 				return n > 0;
82
-			p0++;
83
-			p1++;
84 91
 		}
85 92
 		return false;
86 93
 	}
@@ -195,11 +202,10 @@ void DoSortTest(void)
195 202
 	}
196 203
 }
197 204
 
198
-void RunTest(size_t size)
205
+void RunTest(size_t size, GenerateDataTypes type)
199 206
 {
200 207
 	std::random_device rdev;
201 208
 	std::default_random_engine re(rdev());
202
-	std::uniform_int_distribution<unsigned short> dist(0, 0xff);
203 209
 
204 210
 	if (1)
205 211
 	{
@@ -212,51 +218,139 @@ void RunTest(size_t size)
212 218
 	// generate random number.
213 219
 	data0.clear();
214 220
 	data0.resize(size);
215
-	int16_t tmp = 0;
216
-	printf("Generating random data... (%zu bytes)\n", size);
217
-	for (size_t i = 0, e = size / sizeof(int32_t); i < e; ++i)
221
+
222
+	switch (type)
218 223
 	{
219
-		int16_t x = dist(re);
220
-		int16_t y = (i ^ (tmp << 4)) & 0xff;
221
-		tmp = y;
222
-		reinterpret_cast<int16_t*>(data0.data())[i] = (x << 16) | y;
224
+	case GenUniform32:
225
+		if (1)
226
+		{
227
+			printf("Generating random data... (%zu bytes, type: Uniform32)\n", size);
228
+			std::uniform_int_distribution<uint32_t> dist(0, 0xffffffff);
229
+			for (size_t i = 0, e = size / sizeof(uint32_t); i < e; ++i)
230
+			{
231
+				reinterpret_cast<uint32_t*>(data0.data())[i] = dist(re);
232
+			}
233
+		}
234
+		break;
235
+	case GenUniform16: 
236
+		if (1)
237
+		{
238
+			printf("Generating random data... (%zu bytes, type: Uniform16)\n", size);
239
+			std::uniform_int_distribution<uint16_t> dist(0, 0xffff);
240
+			for (size_t i = 0, e = size / sizeof(uint32_t); i < e; ++i)
241
+			{
242
+				reinterpret_cast<uint32_t*>(data0.data())[i] = dist(re);
243
+			}
244
+		}
245
+		break;
246
+	case GenUniform16Xor: 
247
+		if (1)
248
+		{
249
+			printf("Generating random data... (%zu bytes, type: Uniform16Xor)\n", size);
250
+			std::uniform_int_distribution<uint16_t> dist(0, 0xffff);
251
+			uint32_t tmp = dist(re);
252
+			for (size_t i = 0, e = size / sizeof(uint32_t); i < e; ++i)
253
+			{
254
+				uint32_t x = dist(re);
255
+				uint32_t y = (i ^ (tmp << 3)) & 0xff;
256
+				tmp = y;
257
+				reinterpret_cast<uint32_t*>(data0.data())[i] = (x << 16) | y;
258
+			}
259
+		}
260
+		break;
261
+	case GenUniform8:
262
+		if (1)
263
+		{
264
+			printf("Generating random data... (%zu bytes, type: Uniform8)\n", size);
265
+			std::uniform_int_distribution<uint16_t> dist(0, 0xff);
266
+			for (size_t i = 0, e = size / sizeof(uint32_t); i < e; ++i)
267
+			{
268
+				reinterpret_cast<uint32_t*>(data0.data())[i] = dist(re);
269
+			}
270
+		}
271
+		break;
272
+	case GenUniform8Xor:
273
+		if (1)
274
+		{
275
+			printf("Generating random data... (%zu bytes, type: Uniform8Xor)\n", size);
276
+			std::uniform_int_distribution<uint16_t> dist(0, 0xff);
277
+			uint32_t tmp = dist(re);
278
+			for (size_t i = 0, e = size / sizeof(uint32_t); i < e; ++i)
279
+			{
280
+				uint32_t val = dist(re);
281
+				val = val ^ (tmp << 1);
282
+				tmp = val;
283
+				reinterpret_cast<uint32_t*>(data0.data())[i] = val;
284
+			}
285
+		}
286
+		break;
287
+	case GenNormal64:
288
+		if (1)
289
+		{
290
+			printf("Generating random data... (%zu bytes, type: Normal64)\n", size);
291
+			std::normal_distribution<double> dist;
292
+			for (size_t i = 0, e = size / sizeof(double); i < e; ++i)
293
+			{
294
+				reinterpret_cast<double*>(data0.data())[i] = dist(re);
295
+			}
296
+		}
297
+		break;
298
+	case GenNormal32:
299
+		if (1)
300
+		{
301
+			printf("Generating random data... (%zu bytes, type: Normal32)\n", size);
302
+			std::normal_distribution<float> dist;
303
+			for (size_t i = 0, e = size / sizeof(float); i < e; ++i)
304
+			{
305
+				reinterpret_cast<float*>(data0.data())[i] = dist(re);
306
+			}
307
+		}
308
+		break;
223 309
 	}
224 310
 
311
+	// 1 byte
312
+	DoSortTest<1>();
313
+	// 2 byte
314
+	DoSortTest<2>();
225 315
 	// 3 bytes
226 316
 	DoSortTest<3>();
227 317
 	// 4 bytes
228 318
 	DoSortTest<4>();
229 319
 	// 5 bytes
230 320
 	DoSortTest<5>();
321
+	// 6
322
+	DoSortTest<6>();
323
+	// 7
324
+	DoSortTest<7>();
231 325
 	// 9 bytes
232 326
 	DoSortTest<9>();
233
-	// 16 bytes
234
-	DoSortTest<16>();
327
+	// 10
328
+	DoSortTest<10>();
329
+	// 11
330
+	DoSortTest<11>();
331
+	// 12
332
+	DoSortTest<12>();
333
+	// 13
334
+	DoSortTest<13>();
335
+	// 15
336
+	DoSortTest<15>();
235 337
 	// 17 bytes
236 338
 	DoSortTest<17>();
237
-	// 64
238
-	DoSortTest<64>();
239
-	// 97 bytes
240
-	DoSortTest<97>();
241
-	// 128
242
-	DoSortTest<128>();
243
-	// 512
244
-	DoSortTest<512>();
245
-	// 1024
246
-	DoSortTest<1024>();
247
-	// 4096
248
-	DoSortTest<4096>();
339
+	//// 32 bytes
340
+	//DoSortTest<32>();
341
+	//// 33 bytes
342
+	//DoSortTest<33>();
249 343
 }
250 344
 
251 345
 int main()
252 346
 {
253
-	// Set .error to 'true' to run the test!
254
-	testScore[arkiny].error = true;
255
-	testScore[ccm9026].error = true;
256
-	testScore[djarksnd].error = true;
257
-	testScore[insun].error = true;
258
-	testScore[prauser].error = true;
259
-	testScore[witdrg].error = true;
347
+	// Set .error to '0' to run the test!
348
+	testScore[arkiny].error   = 1;
349
+	testScore[ccm9026].error  = 1;
350
+	testScore[djarksnd].error = 1;
351
+	testScore[insun].error    = 1;
352
+	testScore[prauser].error  = 1;
353
+	testScore[witdrg].error   = 1;
260 354
 
261 355
 	auto PrintScore = [](int phase)
262 356
 	{
@@ -271,7 +365,14 @@ int main()
271 365
 			else
272 366
 			{
273 367
 				uint32_t s = (score.sum / double(score.num)) * 100.0;
274
-				printf("UID(%s) score: %d.\n", uidString[i], s);
368
+				const char* t = "";
369
+				if (s > 100)
370
+					t = "(PERFECT)";
371
+				else if (s > 90)
372
+					t = "(GOOD)";
373
+				else if (s < 60)
374
+					t = "(POOR)";
375
+				printf("UID(%s) score: %d. %s\n", uidString[i], s, t);
275 376
 			}
276 377
 		}
277 378
 		printf("-----------------------------------------\n\n");
@@ -280,7 +381,19 @@ int main()
280 381
 	for (size_t n : testLength)
281 382
 	{
282 383
 		printf("========= Phase %d / %d (%zu) ==========\n", index, int(std::size(testLength)), n);
283
-		RunTest(n);
384
+		for (auto t : {
385
+				GenUniform32,
386
+				GenUniform16,
387
+				GenUniform16Xor,
388
+				GenUniform8,
389
+				GenUniform8Xor,
390
+				GenNormal64,
391
+				GenNormal32
392
+			 })
393
+		{
394
+			RunTest(n, t);
395
+		}
396
+		//RunTest(n, GenNormal64);
284 397
 		PrintScore(index);
285 398
 		index++;
286 399
 	}