Skis / Toys / Fun

Appeal to greatness not guilt

Skis / Toys / Fun

Python vs. Ruby Performance

July 29th, 2008

Not sure why I’m spending the time on this problem, but it looked interesting.  For starters read a Hacker’s News article that mentioned Python vs. Ruby performance, which in turned liked to a polish blog post.

The core of the blog post was this:

20 threads * 100,000 iterations

  1. Ruby 1.9 = 1.54 s.
  2. Ruby Enterprise = 3.01 s.
  3. JRuby 1.1.2 = 5.82 s.
  4. Jython 2.2.1 = 11.86 s.
  5. Python 2.5.2 = 12.32 s.
  6. Ruby 1.8.7 = 22.68 s.

Which is totally amazing for a performance improvement stand point, but in digging further the original code is:

from time import time
from random import Random
from threading import Thread
rand = Random().randint # alias
 
class Test(Thread):
   def __init__ (self):
      Thread.__init__(self)
      print "Starting %s" % self.getName()
   def run(self):
      a = [rand(0,SIZE) for x in xrange(SIZE)]
      a.sort()
      print "%s finished" % self.getName()
 
print "Start"
start = time()
THREADS, SIZE = 20, 100000
threads = []
for i in xrange(THREADS):
    t = Test()
    threads.append(t)
    t.start()
while True in [t.isAlive() for t in threads]:
    pass
print "Time: %s s" % (time() - start)

The first observation is that (unlike the ruby version) the python version has the overhead of a busy wait on the threads, so with than tiny fix (reduced runtime by 1 second)

for t in threads :
    if t.isAlive() :
        t.join()

Time: 17.6256890297 s

Doing a quick decomposition of this, we really have a program that’s doing the following

from time import time
from random import Random
rand = Random().randint # alias
 
THREADS, SIZE = 20, 100000
 
print "Start"
start = time()
 
for t in xrange(THREADS) :
      a = [rand(0,SIZE) for x in xrange(SIZE)]
      a.sort()
 
print "Time: %s s" % (time() - start)

Time: 14.3786399364 s

Not getting into numbers, but this executes in almost the same time as the threaded version… Hmm, so is the ruby version really all about “Threading Performance”? Can’t be, has to be either in the random or the loop… Lets look further.

from time import time
from random import Random
rand = Random().randint # alias
 
THREADS, SIZE = 20, 100000
 
print "Start"
start = time()
 
for t in xrange(THREADS) :
      for x in xrange(SIZE) :
          rand(0,SIZE) 
 
print "Time: %s s" % (time() - start)

Time: 10.9540541172 s

There we have it, the rand() is taking 70% of the total time, while it does appear that the array append overhead is still 30% (~4 seconds) it’s at least useful to notice that there’s nothing that possible to improve it beyond this point.

Conclusion: Ruby might be faster, but to mix up a bunch of performance stats with threading is going to be problematic.

Update: In digging deeper python’s random number generator is written in python, thus of course it’s slow… It’s competing against a C version.

Tags:

Google Knol is not Wikipedia

July 25th, 2008

After giving a few days for the hype to cool down — not the hype around Dark Knight — but around Google Knol.  I think I understand the business and the opportunity and the shortcomings.

In the press, they keep on equating Knol with Wikipedia, which is totally inaccurate:

I personally think the comparison to Wikipedia is inaccurate, it’s really all about croud sourcing about.com.  Let’s do a quick comparison:

  about.com wikipedia google knol
user contributed only editors yes yes
personal profit yes no yes
easy to create no wiki-cabal yes
any subject yes no yes
SEO easy yes yes yes
multiple similar docs yes no yes
authority yes maybe no
       
       

The biggest win of knol is the ability for people to create any arbitrary page about any subject — which you can’t really do in wikipedia (this isn’t a valid wikipedia page:  Learning to Ski — not really about a thing).  While it’s a rich topic area for about.com or for personal blogs, the addtion to knol makes it something where anybody can create a meaninful document.  The downside is that if _you_ disagree with the Learning to Ski page, you have two choices:

  • Contribute your edits back
  • Create your own page

Now this is where the fun begins.  Wikipedia promotes a model by having no personal gain to foster a community of people who create documents and improve documents.  While Google Knol creates a disincentive to create better documents, while it’s possible to set up a document as a collaborative entity, if there’s ad revenue associated with a document, an above average user would be better served by creating a new document and fracturing the market to gain in $$. 

The biggest problem is that right now google knol is being dominated by “doctors” creating pages on medical conditions for personal a gain.  It’s still unclear if as this product matures that it’ll be a collaborate enviornment or a morass of pages and dis-connected content.  Sure, there’s some star ratings to indicate the credibility of the document or author, but will this fundamentally influence the SEO bits on the page.

Tags:

The Silicon Valley is hostile to startups

July 23rd, 2008

Not technology startups, but human startups (aka small business).  At one level you can look around the Silicon Valley and see strip malls full of stores, but if you look closely you’ll see that there is very little variety.  Here’s two examples:

  • Furniture
  • Outdoor Gear

In the furniture case, there is almost no variety of stores in the area.  You either have Ikea, Ethan Allen, or some other chain retailer or you have a strip mall store that’s importing some low cost furniture from the pacific rim (almost all of these stores have the same selection).   What we don’t have is any mid-range dealers, who have broad selection.  What’s different is that when I’m in Reno there are at least a dozen furniture stores that have a variety of choices (from pacific rim to high end).  How can a city of about 200,000 people have better choices than an area of 5M?

Some insight might be gained by looking at outdoor gear, another speciality area.  Here I can name the stores in the area off the top of my head:

  • REI
  • Mel Cotton’s
  • Sports Basement
  • Sun Valley Ski & Patio
  • Any Mountain

If you’ve been paying attention I’ve been looking for some Ski gear in July, which means that outside of being impossible, it’s almost pointless to go shopping locally.  However, in talking with people at work about the problem I did make the following observation, which is:

     Why does Reno have more independent retailers of outdoor & ski gear than the Silicon Valley?

The two theories come to mind:

  • Cost of Labor
  • Cost of Land

Most non-box retailer operate on fairly small margins, so the ability to find and maintain a staff who has some expertise in the goods that you’re selling is going to be very difficult if the cost of labor is high.  In theory in Reno you can make a living working at a sporting goods store or a furniture store.  However in the Silicon Valley that’s impossible!  So, not only are you now faced with hiring sub-standard help (think Fry’s) which really doesn’t serve your customers well.  You’ll also be faced with the double whammy that the cost of land (rent is ~$2-$3 /sqft) is so high that you’re unable to pay a premium for better talent.  Thus you end up in a vicious cycle where you’ve got low margins, high cost of labor and land and as soon as a week month or two come by, you’re dead.

The inability of the Silicon Valley to create a true diverse startup culture, limited to high margin ideas is a true cost.  We tinker but don’t foster tinkers.

Tags:

July in the Silicon Valley

July 23rd, 2008

Can’t be just the high price of gas!  It’s Wednesday and there very little traffic and a pleasant 70 degress outside!  Track was a blast yesterday and not only did I run well (quite a few 75second 400’s) but I’m not sore today and …

 

IT’S A NICE DAY!

Tags:

Shopping out of season

July 21st, 2008

It’s really hard to find ski gear in the middle of summer…

REI sucks, not only is 90% of the clothing closeout, but there isn’t anything outside of rain gear to be found.

Tags:

Before you go half cocked and build a company…

July 11th, 2008

Found this on a old blog that I’m decommissioning — insight from an old WSJ article.

  • Tip 1: Don’t slap your name on just anything to make a buck.
  • Tip 2: Find weaknesses with existing products and fix them. The you can charge more.
  • Tip 3: But raise prices cautiously; make consumers feel they got more than expected and don’t hide company inefficiencies behind price hikes.
  • Tip 4: Seek new consumer bases, and design for them.
  • Tip 5: Invest in products that consumers will always need.

Tags: