#  Tuesday, January 08, 2008
Posted in  | 

We all know how useful a hash table can be, but if you are using the .NET Framework 2.0 you should be using a Dictionary instead. A dictionary and a hash table in .NET 2.0 are very similar but with 1 main difference, a dictionary is faster because it does not need to box and unbox the data as a hash table would.

 

I made a simple program to see just how much faster a dictionary is than a hash table. I ran the test 20 times for each data set and the results were close each time. A GUID as the key and a boolean as the data.

This is the results of the last test for each dataset.

Time in Milliseconds for 100,000 keys Dictionary Hash Table
Inserting 34.41264 76.0970
Reading 18.9005 31.1648
Deleting 21.2474 30.4655

 

Time in Seconds for 10,000,000 keys Dictionary Hash Table
Inserting 6.5704143 26.9096540
Reading 3.1362891 5.6670613
Deleting 3.4623316 4.8830676

 

My comp specs

Vista Business 32bit, AMD 64 x2 5000+, 2GB ram

 

and now for the code I used. You can also download the project.  

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
 
namespace hashVsDictionary
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            #region init
 
            int num = 10000000;
            Guid[] guids = new Guid[num];
 
            Stopwatch s = new Stopwatch();
            s.Start();
 
            for (int i = 0; i < num; i++)
            {
                guids[i] = Guid.NewGuid();
            }
 
            s.Stop();
            Console.WriteLine("Data Creation = " + s.Elapsed);
            s.Reset();
 
            #endregion
 
            #region hash
 
            Hashtable hash = new Hashtable();
            s.Start();
            for (int i = 0; i < num; i++)
            {
                hash.Add(guids[i], true);
            }
            s.Stop();
            Console.WriteLine("Insert Hash = " + s.Elapsed);
            s.Reset();
 
            s.Start();
            for (int i = 0; i < num; i++)
            {
                bool b = Convert.ToBoolean(hash[guids[i]]);
            }
            Console.WriteLine("Extracting Hash = " + s.Elapsed);
            s.Reset();
 
            s.Start();
            for (int i = 0; i < num; i++)
            {
                hash.Remove(guids[i]);
            }
 
            Console.WriteLine("Removing Hash = " + s.Elapsed);
            s.Reset();
 
            #endregion
 
            #region dict
 
            Dictionary<Guid, bool> dict = new Dictionary<Guid, bool>();
            s.Start();
            for (int i = 0; i < num; i++)
            {
                dict.Add(guids[i], true);
            }
            s.Stop();
            Console.WriteLine("Insert Dictionary = " + s.Elapsed);
            s.Reset();
 
            s.Start();
            for (int i = 0; i < num; i++)
            {
                bool b = dict[guids[i]];
            }
            Console.WriteLine("Extracting Dict = " + s.Elapsed);
            s.Reset();
 
            s.Start();
            for (int i = 0; i < num; i++)
            {
                dict.Remove(guids[i]);
            }
            Console.WriteLine("Removing Dict = " + s.Elapsed);
            s.Reset();
 
            #endregion
 
            Console.ReadLine();
        }
    }
}
Tuesday, January 08, 2008 2:18:33 AM (Eastern Standard Time, UTC-05:00)   #     Comments [2] -

#  Thursday, January 03, 2008
Posted in  | 

If you are looking for a ASP.NET Google Map Control, your search is now over.

Jacob Reimers from http://www.reimers.dk/ offers a great asp.net control in 2 flavors.

The free version which lets you easily display a map with markers and/or lines and a licensed version which gives you the full power of Google Maps.

 

I have used this control on a few of Web Solutions clients sites. Two of the better implementations are Low Index and Seville Homes.

 

*The deals listed below are entirely fictional. They were created for presentation purposes only.

 

lowIndex

seville

 

 

 

To use this great control, head over to http://www.reimers.dk/, download the free control, unzip it to your Bin folder in your web app and add a reference to it.

 

This is a sample asp.net page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="GoogleMap" Namespace="Reimers.Map" TagPrefix="Reimers" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Google Map test</title>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <reimers:googlemap id="GMap" runat="server" width="349" height="354" onmarkerclick="GMap_MarkerClick"  />

        </div>

    </form>

</body>

</html>

 

and the code behind

 

using System;

using System.Web.UI;

using Reimers.Map;

 

public partial class _Default : Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        GMap.GoogleKey = "Your API Code here";

        GMap.MapType = MapType.Map;

        GMap.TypeControl = MapTypeControl.None;

        GMap.MapControl = ControlType.Small;

 

        GoogleMarker testMarker = new GoogleMarker("newMarker", new GoogleLatLng(43.611611, -88.952931));

        testMarker.MarkerText = "Test Marker";

        GMap.Markers.Add(testMarker);

 

        GMap.Latitude = testMarker.Latitude;

        GMap.Longitude = testMarker.Longitude;

        GMap.Zoom = 10;

    }

 

    protected void GMap_MarkerClick(GoogleMap GMap, GoogleMarker Marker, ref String MapCommand)

    {

        MapCommand = Marker.OpenInfoWindowHTML(GMap, Marker.MarkerText);

    }

}

Thursday, January 03, 2008 9:33:58 PM (Eastern Standard Time, UTC-05:00)   #     Comments [5] -

#  Wednesday, December 26, 2007
Posted in

Hi,my name is Chris Newman and I'm a 26 year old .Net Rockstar from Troy, Michigan.

I am the Lead Developer at The Web Solutions Company in Mount Clemens Michigan, but soon we will be known as Cafe Live Interactive Media.

I am involved in almost every aspect of the company. I start with the initial consolation with a client and end at Support of the finish product and everything in between.

I have experience with C#, ASP,PHP, C++, C, Assembly, Java, JavaScript, MYSQL, MS SQL, Flash, Flex,Silverlight and much much more.

 

This blog is going to contain my experiences from work, the technology we use, the Open Source Software we use and contribute to, both tools and web technology.

 

As a developer that has completed numerous projects, I am not going to say anything negative about my finished projects as I stand by my work 100%.

I will however talk about the difficulties and solutions that happened during the course of developing.

I will not discuss any relationship with a current or past client. Relationships with tool providers and the tools themselves will be freely discussed.

Wednesday, December 26, 2007 10:39:01 PM (Eastern Standard Time, UTC-05:00)   #     Comments [1] -

Advertisments
Archive
<January 2008>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789
Statistics
Total Posts: 8
This Year: 7
This Month: 0
This Week: 0
Comments: 14
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Chris Newman
Sign In