June 15, 2003
Anagram kata
Here's my JavaScript approach to PragDave's Kata 6: Anagrams. Quite an eyeopener. (Updated version with a threefold performance boost. But still slow!) Performance is just awful. Seventy seconds (on my P3/700 laptop). Am I doing something really wrong? Is there an order-of-magnitude improvement to be had with a clever algorithm? After mulling on it, I don't think so. In the end, I have to just conclude that JScript's hashtable implementation (which is fundamental to the language, since it's the basis for method dispatch) totally sucks. Some associated timing (spurred in part by Tim Bray's recent article): JScript "for( key in table )" turns out to be really really slow. Stunningly, incredibly slow:
If you can build an array (keyed by number) instead of a hashtable (sparse), it's many orders of magnitude faster to count "for( x=0; x < array.length; x++ )". In desperation, I turned to Google, and found that Alan Green has a close-equivalent Python implementation running near one second. It's a relief to see that I'm not obviously a dumb programmer. But is JScript performance really this awful? Please, someone, say I'm missing something...! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vcard
archives: January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 July 2003 June 2003 May 2003 April 2003 March 2003 February 2003 January 2003 December 2002 November 2002 October 2002 September 2002 August 2002 July 2002 June 2002 May 2002 April 2002 March 2002 February 2002 January 2002 December 2001 November 2001 October 2001 September 2001 August 2001 July 2001 June 2001 see also: {groove: [ ray, matt, paresh, mike, jeff, john ], other: [ /* more blogroll to follow */ ] } The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer. RSS 2.0 RSS 1.0 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||