Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

Extreme Optimization #1.1: Mapping IP addresses to country codes.

Rate me:
Please Sign up or sign in to vote.
4.81/5 (34 votes)
30 May 200310 min read 121.7K   2.9K   70  
Highly optimized classes for looking up the country code corresponding to an IP address
// Copyright � 2003 by Jeffrey Sax
// All rights reserved.
// http://www.extremeoptimization.com/
// Filename: timer.cs
// Description: Hi-resolution timer for benchmarking purposes.
// Last modified: April 18, 2003.
using System;

namespace Extreme
{
	public class HiResTimer
	{
		[System.Runtime.InteropServices.DllImport("KERNEL32")]
		private static extern bool QueryPerformanceCounter(ref Int64 lpPerformanceCount);

		[System.Runtime.InteropServices.DllImport("KERNEL32")]
		private static extern bool QueryPerformanceFrequency(ref Int64 lpFrequency);                     

		private Int64 _frequency = 0;
		private Int64 _ticksStart = 0;
		private Int64 _ticksStop = 0;

		public HiResTimer()
		{
			QueryPerformanceFrequency(ref _frequency);
		}

		public void Start()
		{
			_ticksStart = 0;
			QueryPerformanceCounter(ref _ticksStart);
		}
		
		public void Stop()
		{
			_ticksStop = 0;
			QueryPerformanceCounter(ref _ticksStop);
		}

		public void Reset()
		{
			_ticksStart = 0;
			_ticksStop = 0;
		}

		public Single ElapsedSeconds
		{
			get { return (Single)(_ticksStop - _ticksStart) / (Single)_frequency; }
		}
		public Single ElapsedMilliSeconds
		{
			get { return 1000 * ElapsedSeconds; }
		}

		public Int64 Frequency
		{
			get { return _frequency; }
		}
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder Extreme Optimization
Canada Canada
Jeffrey has been writing numerical software for many years. He is founder and president of Extreme Optimization, a Toronto based provider of numerical component libraries for the .NET framework. He loves challenges, especially when it comes to making code run fast, and finding simplicity and elegance in what looks like complicated chaos.

Comments and Discussions