Skip to content

Instantly share code, notes, and snippets.

@clarkzjw
Created January 29, 2015 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkzjw/ba2406a93b99d0e036b6 to your computer and use it in GitHub Desktop.
Save clarkzjw/ba2406a93b99d0e036b6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
#include <cv.h>
#include <highgui.h>
int main()
{
IplImage *img = cvCreateImage(cvSize(5000, 5000), IPL_DEPTH_8U, 1);
cvZero(img);
clock_t begin, end;
int time1, time2;
begin = clock();
for (int i = 0; i < 5000; i++)
{
for (int j = 0; j < 5000; j++)
{
*(uchar *)(img->imageData + (i)* img->widthStep + (j)* img->nChannels) = 100;
}
}
end = clock();
time1 = end - begin;
CvScalar in;
in.val[0] = 100;
begin = clock();
for (int i = 0; i < 5000; i++)
{
for (int j = 0; j < 5000; j++)
{
cvSet2D(img, i, j, in);
}
}
end = clock();
time2 = end - begin;
printf("Time 1: %d clocks\n", time1);
printf("Time 2: %d clocks \n", time2);
cvReleaseImage(&img);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment