{ Code: Impossible } | this = HowI.Roll();

I’ve wrapped up work on v0.4 of the Jsoq Console, and the insanely strenuous release cycle for v0.1 of WhatDidIJustEat.com so I’m starting another side project tonight.

Ever been working with a programming language you’re not 100% familiar with and find yourself wondering:

Is this function a built-in function or in some included library?
What assembly is this class in again?
Can I name my class XXXX without conflicting with another class?

I’ve had these questions recently and found myself annoyed and frustrated to no end (PHP, I’m looking at you) so I’ve decided to build a system to keep track of this stuff for me :D.

The first thing on my list (because it was the easiest) was to do a data dump of all the public classes in the .Net Framework, including the ones in my GAC, and store some metadata for each one in a database table. I’ve just finished this step and thought that this data might be useful, so I’m posting it here.

Currently the fields included in the data dump are:


[namespace] = The namespace that the class exists in (ex: System.Collections.Generic)
[class_name] = The name of the class (ex: StringBuilder)
[assembly_fullname] = The display name of the assembly (ex: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
[assembly_file] = The full file path to the assembly (ex: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll)
[framework_name] = The framework that uses this class, for this dump they will all be 'Microsoft .Net'
[framework_version] = The framework version that uses this class (ex: v.2.0.50727)

The .sql file takes about 18 seconds to run to completion on my AMD Athlon X2 2.53ghz machine with 4gb of RAM.

If you’re curious about how I generated the .sql file, below is the code I used to find all the classes. It’s not pretty but then again it was just meant to get the data into the database. Just paste the code into a new console app and run it in a command window like so:

[application_name].exe > c:\classes.sql

Or, you can download the .sql file I’ve generated (it will also create the table you need to store the data).


static void Main(string[] args)
{
	var dictionary = new Dictionary(){
		{ "v2.0.50727", @"C:\Windows\Microsoft.NET\Framework\v2.0.50727" },
		{ "v3.0", @"C:\Windows\Microsoft.NET\Framework\v3.0" },
		{ "v3.5", @"C:\Windows\Microsoft.NET\Framework\v3.5" },
		{ "v???", @"c:\windows\assembly\gac" }
	};

	var types = new List();

	foreach (var pair in dictionary)
	{
		var path = pair.Value;

		var assemblies = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);

		foreach (string file in assemblies)
		{
			try
			{
				Assembly asm = Assembly.LoadFile(file);

				foreach (Type t in asm.GetTypes())
				{
					if (t.IsPublic)
					{
						Console.WriteLine(String.Format(
							"INSERT INTO Classes (" +
								"[namespace], " +
								"class_name, " +
								"assembly_fullname, " +
								"assembly_file, " +
								"framework_name, " +
								"framework_version" +
							") " +
							"VALUES (" +
								"'{0}', " +
								"'{1}', " +
								"'{2}', " +
								"'{3}', " +
								"'Microsoft .Net', " +
								"'{4}'" +
							")",
							String.IsNullOrEmpty(t.Namespace) ?
								"GLOBAL" :
								t.Namespace,
							t.Name
								.Replace("`1", "")
								.Replace("`2", "")
								.Replace("`3", ""),
							t.Assembly.FullName,
							t.Assembly.Location,
							pair.Key == "v???" ?
								t.Assembly.GetName().Version.ToString() :
								pair.Key
						));
					}
				}
			}
			catch { }
		}
	}
}

If you found this useful, let me know in the comments!

· · ·

Being an uber geek means many things. Late-night code-a-thons just-because, intense debates about zombies vs. pirates vs ninjas (zombies ftw!) or Greedo shooting first, and a desire to have everything running as fast and efficiently as possible.

If you agree with that last sentiment, and you follow everything Google does then you’re probably wondering if Google’s new plans to eventually dominate the entire internet free domain name server lookup service is going to offer you any performance benefits. Well I was wondering the same thing and here is how I determined that it was a good idea to switch.

  1. Download the DNS Performance Test application, extract the zip archive to a folder on your system and run the executable
  2. The app will start and randomize it’s list of URLs. After this is done just click start and switch to the Stats tab
  3. I let the app run for ~500 results to get a good sample of data. After you’re satisfied with the number of results click the stop button and note the “Average Query Time”
  4. Follow Googles directions for switching your DNS over and then repeat steps 1-3 above

After I did those steps I had an average of 213ms for my ISPs DNS and 190ms for Googles. So in my case Google is definitely faster; a 12% increase in DNS lookup performance. So it looks like I’ll be switching over. As for you, well, your mileage may vary.

Did you switch to google? Stay with your current provider? Or maybe you went with OpenDNS? Let me know how it worked out for you in the comments.

·

Turns out, Wolfram Alpha is really handy if you get curious about how many calories are in the lunch you packed for work. Check it out:

Dec/09

2

JavaScript Performance Re-match

Back in 2007 Jeff Atwood ran the top 4 web browsers through the SunSpider JavaScript Benchmark and posted his findings. It’s been close to 2 years since then and I was curious to see how FireFox 3.5, IE8, IE7 (in Compatibility Mode) and Google Chrome 4.0.249.11 would fair.

So I did pretty much the same thing Jeff did and here is what I found:

JavaScript Performance Graph

* System specs: Windows 7 64-bit on a Dual-Core 2.53ghz CPU with 4gb of RAM with no browser extensions

  1. Chrome kicks some serious butt over everyone else with the entire test suite running to completion in under 1 second!!
  2. FireFox 3.5 has some serious improvements coming in at just over 1.5 seconds total, which is about 1/10 the time it took FireFox 2.0
  3. Internet Explorer 8 and Internet Explorer 7 (compat mode) are still bringing up the rear but they had a better showing than the 20+ seconds IE7 took when Jeff ran the test

Surprises?
The only thing I found surprising about the results was that if you removed the string test from both IE runs then IE8 in compatibility mode beats IE8 running normally. That doesn’t seem right to me and I seriously hope JavaScript performance is something that gets addressed in IE9. And by “addressed” I mean “fixed by replacing Trident with WebKit”.

So, what do these results actually mean? Well I guess it depends. If you use your browser to read blogs and check your gmail then you shouldn’t really care about these numbers. However, if you’re a web developer you should be paying strong attention to these numbers and how far they’ve come in just 2 years.

· · ·

Nov/09

25

W.O.M.M. Project Euler #3

works-on-my-machine-starburst

Here we are with another excellent installment in the “Works On My Machine” series where I post some code, some thoughts and hopefully show you something interesting/cool/new.

Today I’m going to talk briefly about Project Euler problem #3. Problem 3 asks you to find the largest prime factor of the number 600,851,475,143.

My solution is pretty simple but it works:


var getLargestPrimeFactor = function(num)
{
    var factors = [];
    for ( var f = 2; f < num; f++ )
    {
        if( num%f == 0 )
        {
            factors.push(f);
            num = num /f;
        }
    }
    factors.push(num);
    return factors[factors.length-1];
};

alert( getLargestPrimeFactor(600851475143));

Try this code!

You may have noticed that there isn’t a check for a factors optimus primeness anywhere in there.

Thats because the getLargestPrimeFactor() function is dividing the number by it’s smallest factor, and the smallest factor for any number is always prime so when we run out of factors we’ve got the largest prime factor. Yeah, that’s pretth cool IMO.

I read the discussion threads for problem 3 after I solved it and I was surprised that hardly anyone removed the prime checks from their code.

So, problem 3 is in the bag and I feel pretty good about coming up with the prime check optimization (or lack thereof). A small bit of proof that I know what I’m doing. Sometimes :D

· ·

<< Latest posts

Older posts >>

Theme Design by devolux.nh2.me