VMs matter
In working on some Smalltalk code (in VisualWorks) on my Mac, things seemed to be running slower than I thought they should. What I was doing was taking a stream of data that represented a bunch of XML “micro-content” and parsing it, then turning it into a new object:
xml := parser parse: (inputStream upTo: Character cr) readStream.
root := xml root.
newData := NormalizedData new.
newData xmlConversionMap keysAndValuesDo:
[:elementName :selector |
newEvent perform: selector
with: (root elementNamed: elementName) characterData].
What that does, for those unfamiliar with Smalltalk code, is read a bit of a stream, up to the end of the line, then turn it into another stream and had than to the parser. That’s boring. The interesting part is the keysAndValuesDo: selector. It runs through a mapping of XML element names to accessors in the new object, and dynamically calls them with the provided data. Perhaps not the fastest, but for me, the most obvious and cleanest way to do this.
On my 1.8Ghz G5 iMac (2Gb RAM), it takes 2.4ms to convert one iteration. On an Athlon64/3000 box, which is 2Ghz and 1Gb RAM, it takes 0.9ms. While some of this difference is in actual processor differences, most of it, I suspect is in the JIT compilation inside the VM. Obviously, the x86 platform is doing a much better job. One hopes that with Apple’s migration to Intel, this will become a non-issue.
One nice thing, though. To do the comparison, I simply moved my image from one machine to the other, and was therefore able to truly do a comparison.
This entry was posted at 10:02 pm on 15 July 2005 and is filed under Smalltalk. You can follow any responses to this entry through the post-specific RSS 2.0 feed.
No comments found.
Both comments and pings are currently closed.