Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Testing simple concurrent containers

, 25 Oct 2009 CPOL
This article illustrates simple approaches and test results when creating containers with concurrent flavor and running on a multi-core PC.
container_locks.zip
Container_locks
src
Testing_simple_concurrent_containers.pdf
VC9
container_locks.vcproj.val-PC.val.user
Debug
tbb_debug.dll
Debug64
tbb_debug.dll
Release
tbb.dll
Release64
tbb.dll
#pragma once

class Performance_counter_meter
{
public:
	Performance_counter_meter()
	{
		m_counter = 0L;
		m_frequency.QuadPart = m_performance_counter_start.QuadPart = m_duration.QuadPart = 0L;
		if ( FALSE == ::QueryPerformanceFrequency(&m_frequency) )
		{
			::RaiseException( STATUS_NONCONTINUABLE_EXCEPTION, 0, 0, 0);
		}
	}
	bool start(void)
	{
		return (::QueryPerformanceCounter(&m_performance_counter_start) != FALSE);
	}
	bool end(void)
	{
		LARGE_INTEGER performance_counter;
		bool rc = (::QueryPerformanceCounter(&performance_counter) != FALSE);
		m_duration.QuadPart += performance_counter.QuadPart - m_performance_counter_start.QuadPart;
		return rc;
	}
	double get_duration(void)
	{
		return (double)m_duration.QuadPart / m_frequency.QuadPart;
	}
	bool get_current_duration(double& duration)
	{
		LARGE_INTEGER performance_counter, counter_duration;
		bool rc = (::QueryPerformanceCounter(&performance_counter) != FALSE);
		counter_duration.QuadPart = performance_counter.QuadPart - m_performance_counter_start.QuadPart;
		duration = (double)counter_duration.QuadPart / m_frequency.QuadPart;
		return rc;
	}
	LONGLONG get_counter(void)
	{
		return m_counter;
	}
	void set_iteration_done(LONGLONG iteration_done)
	{
		m_counter = iteration_done;
	}

private:
	LARGE_INTEGER m_frequency;
	LARGE_INTEGER m_performance_counter_start;
	LARGE_INTEGER m_duration;
	LONGLONG m_counter;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Valery Grebnev
Software Developer
Canada Canada
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 25 Oct 2009
Article Copyright 2009 by Valery Grebnev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid