-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathScreen_Capture_Example.cpp
514 lines (452 loc) · 23.4 KB
/
Screen_Capture_Example.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#include "ScreenCapture.h"
#include "ScreenCapture_C_API.h"
#include "internal/SCCommon.h" //DONT USE THIS HEADER IN PRODUCTION CODE!!!! ITS INTERNAL FOR A REASON IT WILL CHANGE!!! ITS HERE FOR TESTS ONLY!!!
#include <algorithm>
#include <atomic>
#include <chrono>
#include <climits>
#include <iostream>
#include <locale>
#include <string>
#include <thread>
#include <vector>
// THESE LIBRARIES ARE HERE FOR CONVINIENCE!! They are SLOW and ONLY USED FOR
// HOW THE LIBRARY WORKS!
#define TJE_IMPLEMENTATION
#include "tiny_jpeg.h"
#define LODEPNG_COMPILE_PNG
#define LODEPNG_COMPILE_DISK
#include "lodepng.h"
/////////////////////////////////////////////////////////////////////////
void TestCopyContiguous()
{
constexpr auto VALID(static_cast<unsigned char>(0xFF));
constexpr auto INVALID(static_cast<unsigned char>(0xFE));
constexpr auto PIXEL_DEPTH(sizeof(SL::Screen_Capture::ImageBGRA));
constexpr unsigned WIDTH(256), HEIGHT(256);
std::vector<SL::Screen_Capture::ImageBGRA> strided;
for (unsigned row(0); row < HEIGHT; ++row) {
for (unsigned col(0); col < WIDTH; ++col) {
strided.push_back(SL::Screen_Capture::ImageBGRA{VALID, VALID, VALID, VALID});
}
}
auto bytes = strided.size() * PIXEL_DEPTH;
std::vector<unsigned char> contiguous(bytes, static_cast<unsigned char>(0));
auto image = SL::Screen_Capture::Image{{0, 0, WIDTH, HEIGHT}, 0, true, strided.data()};
auto result = SCL_Utility_CopyToContiguous(contiguous.data(), &image);
auto distance = std::distance(contiguous.data(), static_cast<unsigned char *>(result));
if (distance != (WIDTH * HEIGHT * PIXEL_DEPTH))
std::abort();
auto const begin(contiguous.begin()), end(contiguous.end());
for (auto current(begin); current != end; ++current) {
if (*current != VALID)
std::abort();
}
}
void TestCopyNonContiguous()
{
constexpr auto VALID(static_cast<unsigned char>(0xFF));
constexpr auto INVALID(static_cast<unsigned char>(0xFE));
constexpr auto PIXEL_DEPTH(sizeof(SL::Screen_Capture::ImageBGRA));
constexpr unsigned WIDTH(256), HEIGHT(256), PADDING(64), STRIDE_IN_BYTES((WIDTH + PADDING) * PIXEL_DEPTH);
std::vector<SL::Screen_Capture::ImageBGRA> strided;
for (unsigned row(0); row < HEIGHT; ++row) {
for (unsigned col(0); col < WIDTH; ++col) {
strided.push_back(SL::Screen_Capture::ImageBGRA{VALID, VALID, VALID, VALID});
}
for (unsigned pad(0); pad < PADDING; ++pad) {
strided.push_back(SL::Screen_Capture::ImageBGRA{INVALID, INVALID, INVALID, INVALID});
}
}
auto bytes = strided.size() * PIXEL_DEPTH;
std::vector<unsigned char> contiguous(bytes, static_cast<unsigned char>(0));
auto image = SL::Screen_Capture::Image{{0, 0, WIDTH, HEIGHT}, STRIDE_IN_BYTES, false, strided.data()};
auto result = SCL_Utility_CopyToContiguous(contiguous.data(), &image);
auto distance = std::distance(contiguous.data(), static_cast<unsigned char *>(result));
// Ensures that the pointer incremented by only the amount written.
if (distance != (WIDTH * HEIGHT * PIXEL_DEPTH))
std::abort();
auto const begin(contiguous.begin());
auto contiguousEnd(begin), absoluteEnd(contiguous.end());
std::advance(contiguousEnd, WIDTH * HEIGHT * PIXEL_DEPTH);
for (auto current(begin); current != contiguousEnd; ++current) {
if (*current != VALID)
std::abort();
}
for (auto current(contiguousEnd); current != absoluteEnd; ++current) {
if (*current != 0)
std::abort();
}
}
void ExtractAndConvertToRGBA(const SL::Screen_Capture::Image &img, unsigned char *dst, size_t dst_size)
{
assert(dst_size >= static_cast<size_t>(SL::Screen_Capture::Width(img) * SL::Screen_Capture::Height(img) * sizeof(SL::Screen_Capture::ImageBGRA)));
auto imgsrc = StartSrc(img);
auto imgdist = dst;
for (auto h = 0; h < Height(img); h++) {
auto startimgsrc = imgsrc;
for (auto w = 0; w < Width(img); w++) {
*imgdist++ = imgsrc->R;
*imgdist++ = imgsrc->G;
*imgdist++ = imgsrc->B;
*imgdist++ = 0; // alpha should be zero
imgsrc++;
}
imgsrc = SL::Screen_Capture::GotoNextRow(img, startimgsrc);
}
}
using namespace std::chrono_literals;
std::shared_ptr<SL::Screen_Capture::IScreenCaptureManager> framgrabber;
std::atomic<int> realcounter;
std::atomic<int> onNewFramecounter;
inline std::ostream &operator<<(std::ostream &os, const SL::Screen_Capture::ImageRect &p)
{
return os << "left=" << p.left << " top=" << p.top << " right=" << p.right << " bottom=" << p.bottom;
}
inline std::ostream &operator<<(std::ostream &os, const SL::Screen_Capture::Monitor &p)
{
return os << "Id=" << p.Id << " Index=" << p.Index << " Height=" << p.Height << " Width=" << p.Width << " OffsetX=" << p.OffsetX
<< " OffsetY=" << p.OffsetY << " Name=" << p.Name;
}
auto onNewFramestart = std::chrono::high_resolution_clock::now();
void createframegrabber()
{
realcounter = 0;
onNewFramecounter = 0;
framgrabber = nullptr;
framgrabber =
SL::Screen_Capture::CreateCaptureConfiguration([]() {
auto mons = SL::Screen_Capture::GetMonitors();
std::cout << "Library is requesting the list of monitors to capture!" << std::endl;
for (auto &m : mons) {
std::cout << m << std::endl;
}
return mons;
})
->onFrameChanged([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Monitor &monitor) {
// std::cout << "Difference detected! " << img.Bounds << std::endl;
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string("MONITORDIF_") + std::string(".jpg");
auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
auto imgbuffer(std::make_unique<unsigned char[]>(size));
ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
*/
})
->onNewFrame([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Monitor &monitor) {
// Uncomment the below code to write the image to disk for debugging
// auto r = realcounter.fetch_add(1);
// auto s = std::to_string(r) + std::string("MONITORNEW_") + std::string(".jpg");
// auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
// auto imgbuffer(std::make_unique<unsigned char[]>(size));
// ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
// tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char *)imgbuffer.get());
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >=
1000) {
std::cout << "onNewFrame fps" << onNewFramecounter << std::endl;
onNewFramecounter = 0;
onNewFramestart = std::chrono::high_resolution_clock::now();
}
onNewFramecounter += 1;
})
->onMouseChanged([&](const SL::Screen_Capture::Image *img, const SL::Screen_Capture::MousePoint &mousepoint) {
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string(" M") + std::string(".png");
if (img) {
std::cout << "New mouse coordinates AND NEW Image received."
<< " x= " << mousepoint.Position.x << " y= " << mousepoint.Position.y << std::endl;
lodepng::encode(s, (unsigned char *)StartSrc(*img), Width(*img), Height(*img));
}
else {
std::cout << "New mouse coordinates received."
<< " x= " << mousepoint.Position.x << " y= " << mousepoint.Position.y
<< " The mouse image is still the same as the last " << std::endl;
}
*/
})
->start_capturing();
framgrabber->setFrameChangeInterval(std::chrono::milliseconds(100));
framgrabber->setMouseChangeInterval(std::chrono::milliseconds(100));
}
void createpartialframegrabber()
{
realcounter = 0;
onNewFramecounter = 0;
framgrabber = nullptr;
framgrabber =
SL::Screen_Capture::CreateCaptureConfiguration([]() {
auto mons = SL::Screen_Capture::GetMonitors();
auto newmons = std::vector<SL::Screen_Capture::Monitor>();
std::cout << "Library is requesting the list of monitors to capture!" << std::endl;
for (auto &m : mons) {
if (SL::Screen_Capture::Height(m) >= 512 * 2 && SL::Screen_Capture::Width(m) >= 512 * 2) {
SL::Screen_Capture::Height(m, 512);
SL::Screen_Capture::Width(m, 512);
std::cout << m << std::endl;
newmons.push_back(m);
}
}
return newmons;
})
->onFrameChanged([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Monitor &monitor) {
// Uncomment the below code to write the image to disk for debugging
// std::cout << "Difference detected! " << img.Bounds << std::endl;
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string("MONITORDIF_") + std::string(".jpg");
auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
auto imgbuffer(std::make_unique<unsigned char[]>(size));
ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
*/
})
->onNewFrame([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Monitor &monitor) {
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string("MONITORNEW_") + std::string(".jpg");
auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
assert(Height(img) == 512);
assert(Width(img) == 512);
auto imgbuffer(std::make_unique<unsigned char[]>(size));
ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
*/
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >=
1000) {
std::cout << "onNewFrame fps" << onNewFramecounter << std::endl;
onNewFramecounter = 0;
onNewFramestart = std::chrono::high_resolution_clock::now();
}
onNewFramecounter += 1;
})
->onMouseChanged([&](const SL::Screen_Capture::Image *img, const SL::Screen_Capture::MousePoint &mousepoint) {
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string(" M") + std::string(".png");
if (img) {
std::cout << "New mouse coordinates AND NEW Image received."
<< " x= " << mousepoint.Position.x << " y= " << mousepoint.Position.y << std::endl;
lodepng::encode(s, (unsigned char *)StartSrc(*img), Width(*img), Height(*img));
}
else {
std::cout << "New mouse coordinates received."
<< " x= " << mousepoint.Position.x << " y= " << mousepoint.Position.y
<< " The mouse image is still the same as the last" << std::endl;
}
*/
})
->start_capturing();
framgrabber->setFrameChangeInterval(std::chrono::milliseconds(100));
framgrabber->setMouseChangeInterval(std::chrono::milliseconds(100));
}
auto getWindowToCapture(std::string window_to_search_for = "blizzard")
{
auto windows = SL::Screen_Capture::GetWindows();
// convert to lower case for easier comparisons
std::transform(window_to_search_for.begin(), window_to_search_for.end(), window_to_search_for.begin(),
[](char c) { return std::tolower(c, std::locale()); });
decltype(windows) filtereditems;
for (auto &a : windows) {
std::string name = a.Name;
std::transform(name.begin(), name.end(), name.begin(), [](char c) { return std::tolower(c, std::locale()); });
if (name.find(window_to_search_for) != std::string::npos) {
filtereditems.push_back(a);
std::cout << "ADDING WINDOW Height " << a.Size.y << " Width " << a.Size.x << " " << a.Name << std::endl;
}
}
return filtereditems;
}
void createwindowgrabber()
{
auto w = getWindowToCapture();
if (w.empty()) {
std::cout << "In order to test window capturing, you must modify the getWindowToCapture() function to search for a window that actually exists!" << std::endl;
return;
}
realcounter = 0;
onNewFramecounter = 0;
framgrabber = nullptr;
framgrabber =
SL::Screen_Capture::CreateCaptureConfiguration([]() {
auto filtereditems = getWindowToCapture();
return filtereditems;
})
->onNewFrame([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Window &window) {
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string("WINNEW_") + std::string(".jpg");
auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
auto imgbuffer(std::make_unique<unsigned char[]>(size));
ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());
*/
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >=
1000) {
std::cout << "onNewFrame fps" << onNewFramecounter << std::endl;
onNewFramecounter = 0;
onNewFramestart = std::chrono::high_resolution_clock::now();
}
onNewFramecounter += 1;
})
->onMouseChanged([&](const SL::Screen_Capture::Image *img, const SL::Screen_Capture::MousePoint &mousepoint) {
// Uncomment the below code to write the image to disk for debugging
/*
auto r = realcounter.fetch_add(1);
auto s = std::to_string(r) + std::string(" M") + std::string(".png");
if (img) {
std::cout << "New mouse coordinates AND NEW Image received."
<< " x= " << mousepoint.Position.x << " y= " << mousepoint.Position.y << std::endl;
lodepng::encode(s, (unsigned char *)StartSrc(*img), Width(*img), Height(*img));
}
else {
std::cout << "New mouse coordinates received."
<< " x= " << mousepoint.Position.x << " y= " << mousepoint.Position.y << " The mouse image is still the same as the last
"
<< std::endl;
}
*/
})
->start_capturing();
framgrabber->setFrameChangeInterval(std::chrono::milliseconds(100));
framgrabber->setMouseChangeInterval(std::chrono::milliseconds(100));
}
int main()
{
std::srand(std::time(nullptr));
std::cout << "Starting Capture Demo/Test" << std::endl;
std::cout << "Testing captured monitor bounds check" << std::endl;
TestCopyContiguous();
TestCopyNonContiguous();
std::cout << "Checking for Permission to capture the screen" << std::endl;
if (SL::Screen_Capture::IsScreenCaptureEnabled()) {
std::cout << "Application Allowed to Capture the screen!" << std::endl;
}
else if (SL::Screen_Capture::CanRequestScreenCapture()) {
std::cout << "Application Not Allowed to Capture the screen. Waiting for permission " << std::endl;
while (!SL::Screen_Capture::IsScreenCaptureEnabled()) {
SL::Screen_Capture::RequestScreenCapture();
std::cout << " . ";
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
else {
std::cout << "Cannot Capture the screen due to permission issues. Exiting" << std::endl;
return 0;
}
auto goodmonitors = SL::Screen_Capture::GetMonitors();
for (auto &m : goodmonitors) {
std::cout << m << std::endl;
assert(SL::Screen_Capture::isMonitorInsideBounds(goodmonitors, m));
}
auto badmonitors = SL::Screen_Capture::GetMonitors();
for (auto m : badmonitors) {
m.Height += 1;
std::cout << m << std::endl;
assert(!SL::Screen_Capture::isMonitorInsideBounds(goodmonitors, m));
}
for (auto m : badmonitors) {
m.Width += 1;
std::cout << m << std::endl;
assert(!SL::Screen_Capture::isMonitorInsideBounds(goodmonitors, m));
}
std::cout << "Running display capturing for 10 seconds" << std::endl;
createframegrabber();
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Running window capturing for 10 seconds" << std::endl;
createwindowgrabber();
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Running Partial display capturing for 10 seconds" << std::endl;
createpartialframegrabber();
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "Pausing for 10 seconds. " << std::endl;
framgrabber->pause();
auto counti = 0;
while (counti++ < 10) {
assert(framgrabber->isPaused());
std::cout << " . ";
std::this_thread::sleep_for(std::chrono::seconds(1));
}
std::cout << std::endl << "Resuming . . . for 5 seconds" << std::endl;
framgrabber->resume();
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Testing changing the interval during runtime for race conditions " << std::endl;
// HAMMER THE SET FRAME INTERVAL FOR RACE CONDITIONS!!
auto start = std::chrono::high_resolution_clock::now();
while (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now() - start).count() < 10) {
for (auto t = 0; t < 100; t++) {
framgrabber->setFrameChangeInterval(std::chrono::microseconds(100));
framgrabber->setMouseChangeInterval(std::chrono::microseconds(100));
}
}
std::cout << "Changing the cpature rate to 1 second" << std::endl;
framgrabber->setFrameChangeInterval(std::chrono::seconds(1));
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Setting timer using chrono literals" << std::endl;
// You can use chron's literals as well!
framgrabber->setFrameChangeInterval(10ms);
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Testing recreating" << std::endl;
createframegrabber();
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "Testing destroy" << std::endl;
framgrabber = nullptr;
std::cout << "Testing recreating" << std::endl;
createframegrabber();
std::this_thread::sleep_for(std::chrono::seconds(5));
// 4k image
int height = 2160;
int width = 3840;
std::vector<SL::Screen_Capture::ImageBGRA> image1, image2;
image1.resize(height * width);
for (auto &a : image1) {
a.B = static_cast<unsigned short>(std::rand() % 255);
a.A = static_cast<unsigned short>(std::rand() % 255);
a.G = static_cast<unsigned short>(std::rand() % 255);
a.R = static_cast<unsigned short>(std::rand() % 255);
}
image2.resize(height * width);
for (auto &a : image2) {
a.B = static_cast<unsigned short>(std::rand() % 255);
a.A = static_cast<unsigned short>(std::rand() % 255);
a.G = static_cast<unsigned short>(std::rand() % 255);
a.R = static_cast<unsigned short>(std::rand() % 255);
}
long long durationaverage = 0;
long long smallestduration = INT_MAX;
for (auto i = 0; i < 100; i++) { // run a few times to get an average
auto starttime = std::chrono::high_resolution_clock::now();
auto difs =
SL::Screen_Capture::GetDifs(SL::Screen_Capture::CreateImage(SL::Screen_Capture::ImageRect(0, 0, width, height), 0, image1.data()),
SL::Screen_Capture::CreateImage(SL::Screen_Capture::ImageRect(0, 0, width, height), 0, image2.data()));
long long d = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - starttime).count();
smallestduration = std::min(d, smallestduration);
durationaverage += std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - starttime).count();
}
durationaverage /= 100;
std::cout << "Best Case -- Time to get diffs " << durationaverage << " microseconds" << std::endl;
std::cout << "Best Case -- Lowest Time " << smallestduration << " microseconds" << std::endl;
memset(image1.data(), 5, image1.size() * sizeof(SL::Screen_Capture::ImageBGRA));
memset(image2.data(), 5, image2.size() * sizeof(SL::Screen_Capture::ImageBGRA));
durationaverage = 0;
smallestduration = INT_MAX;
for (auto i = 0; i < 100; i++) { // run a few times to get an average
auto starttime = std::chrono::high_resolution_clock::now();
auto difs =
SL::Screen_Capture::GetDifs(SL::Screen_Capture::CreateImage(SL::Screen_Capture::ImageRect(0, 0, width, height), 0, image1.data()),
SL::Screen_Capture::CreateImage(SL::Screen_Capture::ImageRect(0, 0, width, height), 0, image2.data()));
long long d = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - starttime).count();
smallestduration = std::min(d, smallestduration);
durationaverage += std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - starttime).count();
}
durationaverage /= 100;
std::cout << "Worst Case -- Time to get diffs " << durationaverage << " microseconds" << std::endl;
std::cout << "Worst Case -- Lowest Time " << smallestduration << " microseconds" << std::endl;
return 0;
}