JavaScript Benchmarking

I’ve been coding a few functions and methods for an upcoming project and needed to benchmark them. Firebug’s profile tool is pretty good, but it only takes into account one execution of the code – but what if that one instance was particularly slow or particularly fast? For better results, you’d have to repeat the function multiple times to get a better idea of how quick (or slow) it is. So in order to do this, I’ve built a benchmarking tool that bolts onto the Function Prototype:

Function.prototype.benchmark = function(iterations) {
	if(iterations === null || isNaN(iterations) || iterations < 1) { throw new TypeError(); }

	var begin = (new Date()).getTime();

	for(var i = 0; i < iterations; i++) {
		this();
	}

	var end = (new Date()).getTime();

	return (end - begin) / iterations; // in milliseconds
};

Use it like this:

var example = function() {
	// run some code
};

var benchmark = example.benchmark(100); // run example 100 times

In a nutshell, example is executed 100 times and benchmark contains the average time it took in milliseconds to execute it. Obviously more iterations gives a better average but could potentially crash if the number is too high. For big functions and libraries, I'd recommend starting off low (maybe 100) and then ramping it up but for small functions, you could easily start at up to 10,000 or maybe even 100,000. Make sure there isn't any code in there that could potentially ruin the benchmarking - particularly alerts.

Remember to take into account slow machines and portable devices, as not every browser and computer will do it at the same speed.

Panoramas From Tenerife

I was in Tenerife at Easter and made a few panoramas with multiple shots from a Canon IXUS i5 and the Photomerge tool in Photoshop. I’m by no means a photographer so I’d be interested to see what people think.

Unfortunately, these images are only 870 pixels wide (the originals range from 5,500 to 8,500 pixels wide).

Asus Eee PC 1000

After several months of contemplating on the idea of a school laptop, I finally caved in and made the purchase of an Asus Eee PC 1000. I’ve thrown the Windows 7 beta on there and it is absolutely fabulous to use.

The thing that I like most about the Windows 7 beta is that it actually works. You can use it as an everyday operating system almost flawlessly. All the hardware worked from out of the box, with the exception of the Ethernet port and the webcam. Just download the XP Ethernet driver from the Asus support website (the webcam is still something I’m figuring out). Perhaps I should note that installing Windows 7 on the 8GB SSD is not a good idea – stick just a few applications on there and you’ll find you’ve got no space left.

Battery life is about 5 hours from a full charge.

Considering the size of this netbook, it is remarkably easy to type on – even easier than most full-size laptops I’ve used. If you read the articles on the internet, though, there are complaints about the right shift key position. Now considering that I didn’t think I even used the right shift key, let me tell it really is atrocious as I keep hitting the up key instead – almost every time. Most of the other keys are well placed (although the Function keys are a little to the left). The trackpad is also good.

The microphone is OK. Considering that I’ll rarely be using it, it doesn’t really matter. And because the microphone is below the screen, typing is very loud.

Unfortunately, most other netbooks are smaller and although they are significantly cheaper, I wouldn’t recommend getting one with a screen of less than 10 inches. You might think £280 is a lot for such a small machine but it’s the portability, the battery and the quality you get – this thing looks absolutely stunning, the white version looks like a little Macbook. When I’ve got the funds, I’ll be modding it with a touch screen and a GPS dongle.

I should stress the importance of a Wind Surfer to help boost your Wifi signal. Mine went from 2 bars to 4 bars and all it took was a few minutes of printing, cutting and sticking.

Car Insurance

As a 17-year-old male with just (well, soon to be) a newly acquired driver’s license under my belt, I have the privilege of ridiculous car insurance quotes. For a little Volkswagen Golf (1.4 litre), my cheapest quote lies in at £5,000 a year with a slew of more expensive quotes following it (the most expensive being £15,000) – despite the car only being worth £3,000.

If I was to own the car for 4 years, say, it would cost me somewhere in the region of £23,000 excluding tax and petrol. I could either buy the insurance or drive around uninsured in a fleet of 7 VW Golfs – one for every day of the week. Which one would you choose?

A Day Of Video

Having spent the day muxing video, converting it from one format to another and compressing it, I don’t intend to do it again any time soon. There’s just so much you have to take into consideration and even a simple task can become extremely difficult. Because some of the common tasks I had to do were so difficult, I’ll be writing several tutorials to aid anyone else who finds them coerced into the world of video.

Microsoft Math

After a seemingly never-ending torrent of (GCE level) maths homework, I’ve had to turn to Microsoft Math for help. I can’t recommend it enough as it does everything I need it to do. And for $20 (about £10), it’s hardly going to break the bank. Unfortunately, it’s not received an update for about 18 months and it doesn’t appear to be updated any time soon but it’s still a solid piece of software and definitely worth the price. You could even argue that it doesn’t need updating.

Tux?

Want To Cancel An Account With 1&1?

Go to http://contract.1and1.co.uk/ and follow the on-screen instructions. Americans should use http://cancel.1and1.com/. Having just spent the morning in the depths of the 1&1 FAQs, I’ve noticed a lot of tutorials and information that is no longer relevant or no longer works so I strongly advise ignoring it altogether and check other blogs to see how they did it. The differences between the American and British sites are very subtle and usually just boil down to .com and .co.uk. And as I’ve spent a good hour trying to login into the American cancellation site, I can assure you that the customer IDs (more commonly known as Account IDs or a domain name registered with the account) do not work with the wrong site – which, in hindsight, should have been expected.

WordPress 2.7

With the impending release of WordPress 2.7, I thought I’d share some of the new features and styling from the betas.

First thing’s first, the admin pages have seen a big redesign which nicely brings WordPress up to date with trendy drag-and-drop functionality. The new design has a very clean and simple look yet it packs in lots of information, stylishly. It’s not as colourful as 2.6 which worries me in a way as the colours they have used look garish and out of place.

What strikes me most is how integrated WordPress now feels. Once you’ve installed it, you may never need to use FTP again. Plug-in installs and updates can be done within the admin interface – very easily.

Of course, as with many big version overhauls, most plug-ins don’t work and there are quite a few things that I don’t think have been wisely placed. For example, whilst the new navigation strip is a welcome change to the old navigation bar, it is too long and there are quite a few things that I’ll never use. Of course, you can “minimise” it if you wish.

There’s been a big push towards making the interface more customisable and so you are able to remove panes that you don’t like and you can even transform it into a single column display just by dragging the panes into one single column. So in a sense, it feels a lot more like a desktop application.

QuickPress allows you to quickly bash out a post – Twitter-style – and whilst I probably won’t be using it, I can see many who will. Although, with the lack of category selection, its potential is seriously limited.

Added to all these new features, 2.7 also sees a huge number of security fixes and general bug fixes – essentially making this a must-upgrade situation.

Among all the seemingly Web 2.0 traits, 2.7 transforms WordPress into more than just a simple blogging platform. And I dare say that this new version will be one of the major evolutions of WordPress so far.

Windows 7

I’ve recently found myself enticed with all the Windows 7 articles demonstrating things to come from the operating system that’s now being dubbed “what Vista could have been”. And already it certainly looks like Microsoft’s attempt at rectifying all the things that Vista fell down on.

All the legacy programs like WordPad and Paint have been updated and are now in fitting with the new look of Windows. Notably, the calculator has received a large upgrade and it boasts features like conversions, a mortgage calculator and a gas mileage calculator. What previously took a few Google searches and a long-winded Excel spreadsheet can now be done with a few clicks.

Everything just seems to integrate better with Windows 7 as well: changing wireless networks just takes two clicks, the sidebar is no more but the gadgets can roam the desktop and things like Aero Shake suggest (nice but potentially annoying) Compiz Fusion-like effects.

Performance seems to be a lot better than Vista too: everything from shorter boot times to longer laptop battery life seems to be the way that Windows 7 is going. As Vista seemed sluggish compared to its predecessors, I’m excited that Microsoft have turned it back around. It can even run with a mere 1GB of RAM although considering memory is dirt-cheap nowadays, there needn’t be a tiff if it were to require more.

The taskbar has also been hugely redesigned and while I’m not too hot on it at the moment, I’m sure it’ll all fall into place in time. Essentially, the new taskbar makes better use of the space and takes the preview window to the next level.

There’s also promise that Windows 7, from day one, will be more stable than Vista SP1. Whilst I’m not so sure myself, as every new operating system faces numerous bugs, I’m fairly confident that Windows 7 will be a strong OS that should see us through for a good few years.

Oh! How could I forget that they’ve redesigned UAC to be insanely less intrusive? You may be able keep it enabled without losing your insanity. Individual applications can be allowed forever and you can also change the ferocity of UAC, presumably inside the depths of the Control Panel.

All in all, Windows 7 has shaped up to be what could be the best operating system the world has seen. I’m interested in what developments other operating systems will see as Windows 7 nears its launch in mid 2009.