Click here to Skip to main content
15,895,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 3:13
professionalChris Losinger9-Oct-07 3:13 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 3:51
jhwurmbach9-Oct-07 3:51 
GeneralRe: Bitmap-Histogram using MFC [modified] Pin
Chris Losinger9-Oct-07 4:14
professionalChris Losinger9-Oct-07 4:14 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 4:39
jhwurmbach9-Oct-07 4:39 
GeneralRe: Bitmap-Histogram using MFC [modified] Pin
Chris Losinger9-Oct-07 4:44
professionalChris Losinger9-Oct-07 4:44 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 5:21
jhwurmbach9-Oct-07 5:21 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 5:26
professionalChris Losinger9-Oct-07 5:26 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 5:45
jhwurmbach9-Oct-07 5:45 
Chris Losinger wrote:
debug or release


VC++ 7.1. Release mode.
There is so much security built in in Debug, that there is no point comparing with raw C.

Chris Losinger wrote:
if only my customers were so ambivalent about performance!


They are for me. At least for the sub-second delays we are talking about here.

I have added the stdext::hash_map and now I get
map: 57 msec
hash_map: 24 msec
C-Array: 85 msec

Here is my code:
// _Template.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Windows.h"
#include "MMSystem.h"
#pragma comment( lib, "winmm")

#include <tchar.h>
#include <iostream>
#include <map>
#include <hash_map>

#undef max
#undef min

static const int TARGET_RESOLUTION = 1;// 1-millisecond target resolution

int _tmain(int argc, _TCHAR* argv[])
{
	typedef std::map<int, int> HistoMapT ;
	typedef stdext::hash_map< int, int> HashHistoMapT;
	typedef std::pair<int, int> Int_PairT;

	const int w = 1000;
	const int h = 1000;

	//Init Multimedia timer
	TIMECAPS tc = {0};
	UINT     wTimerRes = 5; //default

	if( ::timeGetDevCaps( &tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) 
	{
		std::cout << "Timer Error";
		return system("pause");
	}

	wTimerRes = std::min( std::max( tc.wPeriodMin, (UINT)TARGET_RESOLUTION), tc.wPeriodMax);
	::timeBeginPeriod( wTimerRes); 

	// init to a gradient (also ran init'd to 0s)
	BYTE *p = new BYTE[w * h * 3];
	for (int x=0; x< w;x++)
	{
		for (int y=0;y< h;y++)
		{
			p[x * 3 + y * w * 3 + 0] = w % 256;
			p[x * 3 + y * w * 3 + 1] = h % 256;
			p[x * 3 + y * w * 3 + 2] = (w + h) % 256;
		}
	}

	//Timing of std::map
	const UINT before1 = ::timeGetTime();
	{
		BYTE * pix = p;
		HistoMapT theMap;

		for (int x=0;x< w;x++)
		{
			for (int y=0;y< h;y++)
			{
				const int color_number = RGB(pix[0], pix[1], pix[2]);
				HistoMapT::iterator theIterator = theMap.find(color_number);
				int value = 1;
				if (theIterator != theMap.end() ) 
				{
					value += (*theIterator).second;
				}
				theMap.insert(Int_PairT(color_number, value));

				pix+=3;
			}
		}
	}
	const UINT after1 = ::timeGetTime();

	//Timing of stdext::hash_map
	const UINT before2 = ::timeGetTime();
	{
		BYTE * pix = p;
		HashHistoMapT theMap;

		for (int x=0;x< w;x++)
		{
			for (int y=0;y< h;y++)
			{
				const int color_number = RGB(pix[0], pix[1], pix[2]);
				HashHistoMapT::iterator theIterator = theMap.find(color_number);
				int value = 1;
				if (theIterator != theMap.end() ) 
				{
					value += (*theIterator).second;
				}
				theMap.insert(Int_PairT(color_number, value));

				pix+=3;
			}
		}
	}
	const UINT after2 = ::timeGetTime();

	//Timing of C-Array
	const UINT before3 = ::timeGetTime();
	{	
		BYTE * pix = p;
		int *histo = new int[256 * 256 * 256];
		memset(histo, 0, 256 * 256 * 256 * sizeof(histo[0]));
		for (int x=0;x< w;x++)
		{
			for (int y=0;y< h;y++)
			{
				histo[RGB(pix[0], pix[1], pix[2])]++;
				pix+=3;
			}
		}

		delete [] histo;
	}
	const UINT after3 = ::timeGetTime();

	delete [] p;

	::timeEndPeriod( wTimerRes);
	std::cout << "Elapsed timing map: " << (after1 - before1) << " msec." << std::endl;
	std::cout << "Elapsed timing hash_map: " << (after2 - before2) << " msec." << std::endl;
	std::cout << "Elapsed timing C-Code: " << (after3 - before3) << " msec." << std::endl;

	return system("pause");
}





Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words

GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 5:52
professionalChris Losinger9-Oct-07 5:52 
GeneralRe: Bitmap-Histogram using MFC Pin
jhwurmbach9-Oct-07 5:55
jhwurmbach9-Oct-07 5:55 
GeneralRe: Bitmap-Histogram using MFC Pin
Chris Losinger9-Oct-07 6:09
professionalChris Losinger9-Oct-07 6:09 
QuestionDisable a Menu Option upon right click on a folder Pin
narayanagvs8-Oct-07 22:13
narayanagvs8-Oct-07 22:13 
AnswerRe: Disable a Menu Option upon right click on a folder Pin
chandu0048-Oct-07 22:21
chandu0048-Oct-07 22:21 
AnswerRe: Disable a Menu Option upon right click on a folder Pin
William Engberts8-Oct-07 22:58
William Engberts8-Oct-07 22:58 
GeneralRe: Disable a Menu Option upon right click on a folder Pin
narayanagvs9-Oct-07 1:38
narayanagvs9-Oct-07 1:38 
GeneralRe: Disable a Menu Option upon right click on a folder Pin
narayanagvs9-Oct-07 1:44
narayanagvs9-Oct-07 1:44 
QuestionProblem about Precompiled Header (*.pch) directive Pin
TooShy2Talk8-Oct-07 21:36
TooShy2Talk8-Oct-07 21:36 
AnswerRe: Problem about Precompiled Header (*.pch) directive Pin
Naveen8-Oct-07 21:45
Naveen8-Oct-07 21:45 
GeneralRe: Problem about Precompiled Header (*.pch) directive Pin
TooShy2Talk8-Oct-07 21:58
TooShy2Talk8-Oct-07 21:58 
QuestionHow to update a particular contol? Pin
Sethuraman.K8-Oct-07 21:10
Sethuraman.K8-Oct-07 21:10 
AnswerRe: How to update a particular contol? Pin
Naveen8-Oct-07 21:34
Naveen8-Oct-07 21:34 
AnswerRe: How to update a particular contol? Pin
ThatsAlok8-Oct-07 21:53
ThatsAlok8-Oct-07 21:53 
GeneralRe: How to update a particular contol? Pin
Sethuraman.K8-Oct-07 23:22
Sethuraman.K8-Oct-07 23:22 
GeneralRe: How to update a particular contol? Pin
Hamid_RT9-Oct-07 0:55
Hamid_RT9-Oct-07 0:55 
AnswerRe: How to update a particular contol? Pin
ram.Jaddu9-Oct-07 0:43
ram.Jaddu9-Oct-07 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.