Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Assembler
- //
- // Created by Serge Nanaev on 28.05.17.
- // Copyright © 2017 Serge Nanaev. All rights reserved.
- //
- #include <iostream>
- #include <ctime>
- #include <sys/time.h>
- float timedifference_msec(struct timeval t0, struct timeval t1) {
- return (t1.tv_sec - t0.tv_sec) * 1000.0f + (t1.tv_usec - t0.tv_usec) / 1000.0f;
- }
- int main(int argc, const char * argv[]) {
- int checkNumber = 45;
- int arraySize = 250;
- int array[arraySize][arraySize];
- for (int i = 0; i < arraySize; i++) {
- for (int j = 0; j < arraySize; j++) {
- array[i][j] = rand() % 100;
- }
- }
- struct timeval t0;
- struct timeval t1;
- float elapsed;
- gettimeofday(&t0, 0);
- for (int n = 0; n < 1000; n++) {
- for (int i = 0; i < arraySize; i++) {
- int sum = 0;
- for (int j = 0; j < arraySize; j++) {
- sum += array[i][j];
- }
- int avg = sum/arraySize;
- //std::cout << avg << '\n';
- if (avg < checkNumber) {
- //std::cout << "Find it! \n";
- }
- }
- }
- gettimeofday(&t1, 0);
- elapsed = timedifference_msec(t0, t1);
- printf("Code executed in %f milliseconds.\n", elapsed);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement