Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <chrono>
- typedef std::chrono::high_resolution_clock Clock;
- unsigned check(int *Items, int & Count)
- {
- int max = 0, start = 0, end = 0;
- while (Count--)
- {
- if (Items[Count] > max)
- {
- max = Items[Count];
- start = end = Count;
- }
- else if (Items[Count] == max) end = Count;
- }
- return start == end ? 0 : (start - end - 1);
- }
- void test()
- {
- int iterations = 1000000, cur = 0, count = 20;
- int items[20] = { 1, -1, 30, 44, 55, 44, 22, 1, 0, -12, 33, 95, 0, 2, 95, -10, 95, 33, 22, 95 };
- std::chrono::time_point<std::chrono::steady_clock> before, after;
- long float AVG = 0;
- while (cur < iterations)
- {
- before = Clock::now();
- check(items, count = 20);
- after = Clock::now();
- AVG += std::chrono::duration_cast<std::chrono::nanoseconds>(after-before).count();
- ++cur;
- }
- printf("AVG time per %d iterations.\nIn nanoseconds\nTotal: %f\nAvg: %f \n", iterations, AVG, AVG / iterations);
- }
- int main()
- {
- test();
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement