Skip to content

Instantly share code, notes, and snippets.

@Kobzol
Created September 29, 2016 07:04
Show Gist options
  • Save Kobzol/030a01b0e100b774e5bfcbf7dee1d5ea to your computer and use it in GitHub Desktop.
Save Kobzol/030a01b0e100b774e5bfcbf7dee1d5ea to your computer and use it in GitHub Desktop.
Loop unrolling
#include <iostream>
void for1(int x)
{
int* arr = new int[x];
for (int i = 0; i < x; i++)
{
arr[i] = i;
}
delete[] arr;
}
void for2(int x)
{
int* arr = new int[x];
int end = x / 4;
for (int i = 0; i < end; i++)
{
arr[i] = i;
arr[i + 1] = i + 1;
arr[i + 2] = i + 2;
arr[i + 3] = i + 3;
}
delete[] arr;
}
int main()
{
const int count = 4 * 1000 * 1000 * 100;
clock_t s = clock();
for1(count);
//for2(count);
clock_t end = clock() - s;
std::cout << (end / 1000) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment