Commit 4e3165e6bcc930790d9d428df0c2359555d9c4d8

Con Kolivas 2014-05-10T22:11:47

Rework the benchmarking code to use a deterministic set of work items with a known number of diff share nonces at regular spaced intervals

diff --git a/bench_block.h b/bench_block.h
index a1aa35a..d83bb1a 100644
--- a/bench_block.h
+++ b/bench_block.h
@@ -1,39 +1,171 @@
-#if !defined(__BENCH_BLOCK_H__)
-	#define __BENCH_BLOCK_H__ 1
-
-	// Random work pulled from a pool
-        #define CGMINER_BENCHMARK_BLOCK                                                                         \
-                0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0xD8, 0x07, 0x17, 0xC9, 0x13, 0x6F, 0xDC, 0xBE, 0xDE, 0xB7, \
-                0xB2, 0x14, 0xEF, 0xD1, 0x72, 0x7F, 0xA3, 0x72, 0xB2, 0x5D, 0x88, 0xF0, 0x00, 0x00, 0x05, 0xAA, \
-                0x00, 0x00, 0x00, 0x00, 0x92, 0x8B, 0x4C, 0x77, 0xF5, 0xB2, 0xE6, 0x56, 0x96, 0x27, 0xE0, 0x66, \
-                0x3C, 0x5B, 0xDD, 0xDC, 0x88, 0x6A, 0x7D, 0x7C, 0x7B, 0x8C, 0xE4, 0x92, 0x38, 0x92, 0x58, 0x2E, \
-                0x18, 0x4D, 0x95, 0x9E, 0x4E, 0x44, 0xF1, 0x5F, 0x1A, 0x08, 0xE1, 0xE5, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, \
-                0x86, 0x7E, 0x3A, 0xAF, 0x37, 0x83, 0xAF, 0xA0, 0xB5, 0x33, 0x2C, 0x28, 0xED, 0xA9, 0x89, 0x3E, \
-                0x0A, 0xB6, 0x46, 0x81, 0xC2, 0x71, 0x4F, 0x34, 0x5A, 0x74, 0x89, 0x0E, 0x2B, 0x04, 0xB3, 0x16, \
-                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
-                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0xF6, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, \
-                0x55, 0xF1, 0x44, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x79, 0x63, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, \
-                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,                                                 \
-
-#endif // !defined(__BENCH_BLOCK_H__)
+#ifndef __BENCH_BLOCK_H__
+#define __BENCH_BLOCK_H__
+
+/* This contains 32 carefully chosen work items, 16 of which return diff >= 32
+ * at nonces spaced ~ 0x00100000 apart and 16 < diff 32 spaced ~ 0x01000000
+ * apart. */
+
+const char bench_hidiffs[16][324] = {
+// 0002108b diff 131
+"000000029c6bf469abe4ad37605c097a860cff3cf5c1ef4377618f74000000000000000082b1514e7b6565941e5824f084292164ec5f97e7ea20c494bd96e524d478977b536dd2261900896c8b100200"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"64e4e3becc01064d808269b330f40f4de82dc92e894d635025daa3e2e2c410b4",
+
+// 1003dacf diff 37
+"00000002e790c23987181950eeb144591c3ac4d06c0705f2801d097600000000000000009ebbce2f5f0d6cc0aca284ecb1059c856ef2f7f42e7edd403d246754ee4c905a536dd2a91900896ccfda0310"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"4a78daf1b5eb3397af1c00dbd9b06659cdc04183c8baaf5be1dbf32f79e00459",
+
+// 200e57b4 diff 3866
+"000000023e91fce7300a792bfbaa0c76e1aa5f9b546c1db582aee4ff0000000000000000f04650a8e748d2e6fde86a8a920b285f3e22398f583700236958323ef9ea8321536dcf431900896cb4570e20"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"0a1d654ae2b06f219ccf4601933fab408de1c3b7c8c9c85e03231d4aaf5a26cd",
+
+// 300f71e2 diff 335
+"000000023e91fce7300a792bfbaa0c76e1aa5f9b546c1db582aee4ff000000000000000074b39134c2930d2f2e7339f9d502c776c44d6ee599f7efebec6c9bbd04787aae536dce561900896ce2710f30"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"94e60c1180022f337232ab3d298f838304b6008ab237cf7e1717f1933407e592",
+
+// 400548ed diff 2670
+"000000023e91fce7300a792bfbaa0c76e1aa5f9b546c1db582aee4ff0000000000000000c5b821fb0b26d63b00cc26e7ac4d6cfd1d3fc109b0db188e7e792e3d18342919536dce501900896ced480540"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"a290eac61642949c00d17f7cd5980abedb8647fc5df9955dcfe4d56a50a0c564",
+
+// 5001f760 diff 60
+"00000002e790c23987181950eeb144591c3ac4d06c0705f2801d097600000000000000006e9d94bf5a0ab7b202d39e1200af96074e4f641f4e55e3e9e3aee72aa00a70e9536dd2ae1900896c60f70150"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"1477ca8536702eacbd65a6a162cfe90d62016a14ffe58d52b7dd4c3628a27e5b",
+
+// 600c9816 diff 35
+"00000002194bb5b4f8ac3392fbd66f3dd3e9dcdb22370e380837fe44000000000000000003bbb250f2dc23717e8192c0b8bec6a175cd059e4089d325006eaee3446254c9536dd39e1900896c16980c60"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"68db599d6b7a55fd61d4244a3dfa465055ead6b5c0a37c7a3d4555b58e99065e",
+
+// 70092d5f diff 114
+"000000023e91fce7300a792bfbaa0c76e1aa5f9b546c1db582aee4ff000000000000000072e17babd4089b204797cebda7dc6e277950eab1b2908991ae1d72335f82d204536dcf441900896c5f2d0970"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"c7d601ce3b01e569a49508d541bbcba9b3c8394b1834523ef1e5cb2c60bd34a3",
+
+// 800eeaa8 diff 159
+"000000029c6bf469abe4ad37605c097a860cff3cf5c1ef4377618f74000000000000000022388b6f022144db134af1bc8e61b385ca37cae038c1d165ae98c496b3b41e8b536dd2101900896ca8ea0e80"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"410761e97e67b494fd547cfe9ffbb36893da7aec75c6b51b8d5f38f87b5d63cf",
+
+// 900f600d diff 144
+"000000029c6bf469abe4ad37605c097a860cff3cf5c1ef4377618f7400000000000000000e1f0cfdf5ad8248fc4520f3bb0b2040226430348cddeff5ca9181beeb78870d536dd2161900896c0d600f90"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"ad1a8d354a7e8b13ec47f4c3d907d00945a61e86059f4943e42c1e52398eba5d",
+
+// a00210bf diff 1055
+"00000002194bb5b4f8ac3392fbd66f3dd3e9dcdb22370e380837fe4400000000000000002232a16d38cc0e13e4b16d917bff4c34727deb3b5c50e424fb8453ff9b2adcb4536dd4231900896cbf1002a0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"adc67d38f31f589b18b9d8e531b994ce5733c021a03d88d38611ee6b4c2710a5",
+
+// b004309d diff 43
+"00000002194bb5b4f8ac3392fbd66f3dd3e9dcdb22370e380837fe440000000000000000a2860471277b4a93fea2a8b6d8c281fab7bde3b78f2acd1bfdc89d464ed3bb3c536dd35e1900896c9d3004b0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"537686c611aae4397c7c04b2c190708453d00e8c9563525610c31ba46e80dbc2",
+
+// c00b7537 diff 64
+"00000002194bb5b4f8ac3392fbd66f3dd3e9dcdb22370e380837fe440000000000000000f370230607998fbbd10275c5890885fcd81b68018ba2373abf0f93a06d02ab28536dd33e1900896c37750bc0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"1fdda952da6abd70022a6e5f2b9dc5e1b66011128c3fa249f0b7439f00d5943e",
+
+// d0005bd5 diff 1539
+"00000002c0a2c91fc41254539a5b2a27be28de2a6187e2af3f129d6300000000000000005e45ffc512d5ca3bc4d2063dd3af1669c296ae126a5a2ef896d1e190cedf67b9536dd46b1900896cd55b00d0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"07094d6cbe76538a88612624fc5e655cc405cb8198dcad516b88dbac5bf8b906",
+
+// e00a7796 diff 41
+"00000002194bb5b4f8ac3392fbd66f3dd3e9dcdb22370e380837fe44000000000000000027c548815127c125147af91c356c293f0defbd2771f8dc3b1142b367528656db536dd37c1900896c96770ae0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"1bdbb3b1be7216872ea787627b03c389a527451f6dd832d8540874306f9c07c6",
+
+// f001f029 diff 77
+"00000002194bb5b4f8ac3392fbd66f3dd3e9dcdb22370e380837fe440000000000000000adef758770bb90c5b13769c5b61affb322b24c747573b38ebe2ee81748d0b557536dd4071900896c29f001f0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"1ac8eea63285353944e40eec54d2dd6cd0994b447429bb0ed0598d38f42da0e2"
+};
+
+const char bench_lodiffs[16][324] = {
+// 000ed6b6 diff 2
+"00000002c01f502cb3e9fdb053230ec12a4954c1021a6b35862b5e29000000000000000084d1b83ae44057025e8c5b5756b44f04df5fffe4a7a30e5c12d12a97a7a4c2ea536dce431900896cb6d60e00"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"d08f7e14c50dad77dc238b4db2901a0578e657b1954779ab9cd82a73829edf7f",
+
+// 1000818f diff 5
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a44630000000000000000c1a174254a6593ffba987f68fe26e716e3c129a7f33a9c43ae7ecf90c8cd0d2c536dc4e61900896c8f810010"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"6700aeedada2b3877900b58a183c42c40949956bb8b4a8d21481f8936b572922",
+
+// 20006be9 diff 7
+"00000002138cf4b61dff74e3c26b2d80045064e8ab4802521bab2cda000000000000000071eef64a7ef4e47cda16e96673197d36c7235a4aadd23c21a38ce53827d1f8bc536dc4d71900896ce96b0020"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"0730cf7a6b8a85eb1cc017b109d23c392464f99aa8c020ea107c525b671adde0",
+
+// 300029f4 diff 2
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a44630000000000000000fe2c6b926468565e524ab7c2f111035dcde7c60955842111930589eccb410f83536dc66b1900896cf4290030"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"27dbb374a97f15c59587256662f36904d075d0e61f749618182711288ac617c7",
+
+// 40001d82 diff 2
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a4463000000000000000003073385e05c29f0435a6001c8eca9c8d5602890aeff9d4d103d3383cf80dae5536dc57c1900896c821d0040"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"7da3b97e82c0c3125a58dad8a0d1d0369244731f3b096e972484298d15b843d9",
+
+// 50003ce6 diff 1
+"000000029ca55e5f1bc0328c84f358fddadc13cb232599bc2ca9dbe10000000000000000b5b4d19c20a7fc2b174ff673c006edd2247c4b2336571864df93eb7ec0c8c276536dfe041900896ce63c0050"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"1514bd586511e531e2b6277a6d112b171f9e008d56ef4a971e619acf22e75072",
+
+// 60004314 diff 2
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a446300000000000000003e3030629ff4258056dc9efaf922bd173a65f65ee799b0c765097d3deeddef10536dc4d81900896c14430060"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"dcb77a9c36d894d2dbc31437e5c2a1564e927937848ea2eb20b38638afc64b96",
+
+// 700041d4 diff 7
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a446300000000000000005513c22bb99e9daa9936b0df5dce64d7737e3706be99e5098d112002492cf81b536dc5691900896cd4410070"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"0d896267fda5dda0f85308e77f754c8b94b7b88e3cb315475cd9efd16401e3ce",
+
+// 80009d99 diff 1
+"00000002e155f07e652e4d671ca4db51bbde14d2b5ae34ee67ecc74400000000000000004af5cffd7e5a7087f1b484b526c7350c86d8389283509ca878502f792115e8dc536dc6ad1900896c999d0080"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"339354568f506ac3cd69bb427b1af83a0473b87c16bf3b562a93d0a2ffc53e54",
+
+//  9000fb14 diff 4
+"000000029ca55e5f1bc0328c84f358fddadc13cb232599bc2ca9dbe100000000000000005925a624e5c84f96d2c34dce3b6a736addb891724b48a36320c7494435f9c915536dfe621900896c14fb0090"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"8362009c07cf48249f481be6b79e67247cab1d20050cf11c276085b90732110c",
+
+// a000eb5e diff 2
+"00000002e155f07e652e4d671ca4db51bbde14d2b5ae34ee67ecc74400000000000000001e69f1d6507f4b7b50980930f7d8089834fbe65f0980b8592d53cdda08e50d24536dc7da1900896c5eeb00a0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"21e4f654d26ab8c9164ff311657a9f9c4cdc0e8a09334925f7c02138819d7e61",
+
+// b0002ec5 diff 2
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a4463000000000000000064923b63f53c72c04ebe6c1c9140b6377132b6e50865814fe562291bd023d348536dc65a1900896cc52e00b0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"55db91a25401a89daf9ff7d7954bab722b894ba480fefaf1f0a95aaf5f600567",
+
+// c0001f6e diff 2
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a44630000000000000000ee9817160e35d4410601c8dc741c1a810c485f3b40a0859be5f58f0bf6ef1694536dc6321900896c6e1f00c0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"ae215785178ff6350064060ebbb219a71716a10e88528fc4bb1cb5c8fdd0cf60",
+
+// d0005f26 diff 7
+"000000029ca55e5f1bc0328c84f358fddadc13cb232599bc2ca9dbe100000000000000001e514cf738455a54f004ec86edafcfd9fd2022017bb31c245340353911744fb7536dfe1f1900896c265f00d0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"dcafaa86defe850b057ae74f7218a79b0ede086a196f18f0e7c585eb88d1139a",
+
+// e0008993 diff 2
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a446300000000000000005edbd53fcc64850b5334678199d769514818fbcc79861fc77e572bb4753b7fe2536dc5d91900896c938900e0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"5e653df5956ece518a78a5d11297431af94ce8ba91d80cfb2aa8c5b3095fa256",
+
+// f000709e diff 1
+"000000023bf53ef343a50f7599601f849c93ecce63530b0b449a44630000000000000000596fc4aa5da839ba267c36aa1a5b29d813747b2273dc03aa9e404c4da0238e2b536dc4cc1900896c9e7000f0"
+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
+"0e23806a533bd956787eef52dd8edee456c60d6cecbb6175458ee53fc8c6c813"
+};
+#endif /* __BENCH_BLOCK_H__ */
diff --git a/cgminer.c b/cgminer.c
index 2ca6972..98c9c7b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3460,22 +3460,35 @@ static void calc_diff(struct work *work, double known)
 	}
 }
 
+static unsigned char bench_hidiff_bins[16][160];
+static unsigned char bench_lodiff_bins[16][160];
+static unsigned char bench_target[32];
+
+/* Iterate over the lo and hi diff benchmark work items such that we find one
+ * diff 32+ share every 32 work items. */
 static void get_benchmark_work(struct work *work)
 {
-	// Use a random work block pulled from a pool
-	static uint8_t bench_block[] = { CGMINER_BENCHMARK_BLOCK };
-
-	size_t bench_size = sizeof(*work);
-	size_t work_size = sizeof(bench_block);
-	size_t min_size = (work_size < bench_size ? work_size : bench_size);
-	memset(work, 0, sizeof(*work));
-	memcpy(work, &bench_block, min_size);
+	static int hidiff = 0, lodiff = 0;
+	static int direction = 1;
+
+	lodiff += direction;
+	if (lodiff < 1)
+		direction = 1;
+	if (lodiff > 15) {
+		direction = -1;
+		if (++hidiff > 15)
+			hidiff = 0;
+		memcpy(work, &bench_hidiff_bins[hidiff][0], 160);
+	} else
+		memcpy(work, &bench_lodiff_bins[lodiff][0], 160);
+	work->work_difficulty = 32;
+	memcpy(work->target, bench_target, 32);
+	work->drv_rolllimit = 0;
 	work->mandatory = true;
 	work->pool = pools[0];
 	cgtime(&work->tv_getwork);
 	copy_time(&work->tv_getwork_reply, &work->tv_getwork);
 	work->getwork_mode = GETWORK_MODE_BENCHMARK;
-	calc_diff(work, 0);
 }
 
 static void benchfile_dspwork(struct work *work, uint32_t nonce)
@@ -7030,6 +7043,22 @@ static void submit_work_async(struct work *work)
 	pthread_t submit_thread;
 
 	cgtime(&work->tv_work_found);
+	if (opt_benchmark) {
+		struct cgpu_info *cgpu = get_thr_cgpu(work->thr_id);
+
+		mutex_lock(&stats_lock);
+		cgpu->accepted++;
+		total_accepted++;
+		pool->accepted++;
+		cgpu->diff_accepted += work->work_difficulty;
+		total_diff_accepted += work->work_difficulty;
+		pool->diff_accepted += work->work_difficulty;
+		mutex_unlock(&stats_lock);
+
+		applog(LOG_NOTICE, "Accepted %s %d benchmark share nonce %08x",
+		       cgpu->drv->name, cgpu->device_id, *(uint32_t *)(work->data + 64 + 12));
+		return;
+	}
 
 	if (stale_work(work, true)) {
 		if (opt_submit_stale)
@@ -9238,6 +9267,12 @@ int main(int argc, char *argv[])
 		enable_pool(pool);
 		pool->idle = false;
 		successful_connect = true;
+
+		for (i = 0; i < 16; i++) {
+			hex2bin(&bench_hidiff_bins[i][0], &bench_hidiffs[i][0], 160);
+			hex2bin(&bench_lodiff_bins[i][0], &bench_lodiffs[i][0], 160);
+		}
+		set_target(bench_target, 32);
 	}
 
 #ifdef HAVE_CURSES