Friday, June 5, 2009

Language Benchmarks and Psyco Python

0 comments

Ever wonder about how fast certain programming or scripting languages are, versus one another? Well, I have...

The Premise

So, being that MacPorts has Psyco available to it, I've been playing around with it. For those of you not in the know, Psyco is a JIT compiler and optimizer for Python. I came across this page of benchmarks and thought it would be fun to play around with the various implementations and see how fast they got.

The Machine

For the tests, I'm using my MacBook Pro (2.8 GHz Intel Core 2 Duo w/6MB L2, 4 GB DDR3 @ 1 GHz). As for the software:

ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
This is perl, v5.8.9 built for darwin-2level
Python 2.6.2 (r262:71600, Jun  5 2009, 17:59:46)
    [GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153)
    Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)
gcc (GCC) 4.4.0

Additional parameters passed to GCC:

c-regular: gcc bench.c
c-nocona:  gcc -O3 -march=nocona -m64 bench.c
c-tuned:   gcc -O3 bench.c

The Code (with Psyco)

I modified all of the scripts to get rid of their built-in timing, preferring instead the time UNIX command (real). Also, I stopped them from actually printing the fractal, but kept in the various 'print' commands as some of the implementations require at least something in their if-else block.

#!/usr/bin/env python
# by Daniel Rosengren
# Modified by Sebastian Weigand

import sys, psyco
stdout = sys.stdout

psyco.full()

BAILOUT = 16
MAX_ITERATIONS = 1000

class Iterator:
  def __init__(self):
    for y in range(-39, 39):
      for x in range(-39, 39):
        i = self.mandelbrot(x/40.0, y/40.0)
        
        if i == 0:
          stdout.write('')
        else:
          stdout.write('')
    
  def mandelbrot(self, x, y):
    cr = y - 0.5
    ci = x
    zi = 0.0
    zr = 0.0
    i = 0

    while True:
      i += 1
      temp = zr * zi
      zr2 = zr * zr
      zi2 = zi * zi
      zr = zr2 - zi2 + cr
      zi = temp + temp + ci
     
      if zi2 + zr2 > BAILOUT:
        return i
      if i > MAX_ITERATIONS:
        return 0

Iterator()

You can easily download the other files here, and run the benchmarks for yourself.

The Results

Well, as you might expect, they are a tad bit faster than the PowerBook in question. I just took a few of the tests, and came out with these results:

Benchmark bars

It's amazing just how much faster Psyco can make Python!

Interesting too, how unless you've got some really high-end SSE3 or higher code, with lots of matrices and whatnot, GCC won't make your code that much faster if you have it match your current high-end CPU. This holds true for a lot of things actually (like Vorbis). See what I mean by adjusting the MAX ITERATIONS to something like 100,000 or so.

Any thoughts on Psyco?

Sunday, May 31, 2009

Google Chrome for Mac Status (with pictures)

0 comments
Chromium Icon

It's a browser!

I'm very pleased that it builds, and works without much fuss. I'm not quite sure whether it's capable of replacing Safari for now, but it's definitely a start (provided you download the 3 GB worth of source code). And here's what it looks like:

Rendering my blog

img class=

Good job there, though it isn't surprising as it's taking most of its rendering codebase from Webkit. It does a great job, keeping everything looking great in the process.

Acid3 Test

img class=

Apropos, it's an older version of Webkit. Newer ones are fully Acid3-compliant.

Home Screen

img class=

It seems like every browser is now coming with its very own 'home-screen'. Well, except Firefox (but there's probably a plugin) and IE.

V8 Benchmark

img class=

For reference, Webkit (build 5528.17, r44282) gets around 2,600 on the same hardware under OS X. V8 I guess is tricky to optimize on the Mac, and considering what its doing, I'm not surprised.

Processes

img class=

Now, I know what you might think, but it's actually not crashing, it's just that Chromium does not delegate CPU to inactive tabs (much), so it shows up as "Not responding". It'd be the same (sort of) if you ran any app from the Terminal, but backgrounded it. Also, make sure you understand how Activity Monitor and OS X calculate and handle virtual memory, before complaining.

Oopsies

img class=

Maybe they should've put a big TODO here, lol.

Other things that I noticed which aren't finished yet would include a lack of a status bar on the bottom (especially important for downloading things), and plugins such as Flash. It's interesting that the Mac Flash plugin wouldn't work.

In summary

I'm very happy to see that TONS of progress has been made on this project (seriously, I'm not being sarcastic). On Windows, I was blown away by the browser's capabilities and simplicity, and I suspect it will become my new browser of choice when it gets around to being officially released on the Mac.

Jeeze, I'm really tired of waiting for good FOSS projects!

iPhoto '09 and Facebook

0 comments

I've been playing around with iPhoto '09 recently (specifically for Apple's implementation of facial detection and recognition), and (almost obviously) I have a big complaint.

Facebook contact misconnections

After I tagged people via Faces, and uploaded them to Facebook, I was surprised that several of my contacts, though having the exact same name as they do on FB, were not matching up.

I wondered why, then I wondered how. I believe the methodology of 'matching' contacts is done via email. Unfortunately, my address book on my laptop (which acts as my master book, because it synchronizes with Google and my iPhone) does not contain all the oddball email addresses used by my friends with their Facebook accounts. Even me, when I set up my Facebook account, didn't use my good email account, and used an alternative. This goes for a lot of people, really. Now, here are some solutions

Assume people take pictures of friends

For the most part, people will be taking pictures of their friends, which would theoretically limit the amount of duplicate names which can sprout up from attempting to match my friend 'Joe Schmoe' with all the 'Joe Schmoes' on Facebook.

Use Bayesian statistics to pinpoint contact matching

Instead of matching contacts via true or false, 1 or 0 boolean hits based on email addresses, use a combination of first name, last name, screen name, and email address to come up with a significant percentage chance of this 'Joe' matching my friend Joe.

Cache contact matching information

Once the database of matches is created, confirm with the user that the contacts are the same (probably for any low-confidence matches, to avoid annoyance), and store the details. Facebook assigns a GUID to every account, which can be used to more accurately pinpoint contacts should their information either on the client or the server changes. This way, when iPhoto 'tags' someone, it does so via the GUID, and always hits its mark. Note: Here, it doesn't really matter if the client or the server (ideally the server) stores the cached matches, just that someone does.

Allow for modification of the database

If we need to change something down the line, or make errors, let's make sure we can. This way, if the GUID scheme changes, we can rebuild the database with the new naming convention.

Provide address book synchronization capabilities

Seriously Facebook, you need to get on this. As nice as you are for keeping in touch with friends (and having them annoy the hell out of me via crappy applications which litter up my home page), all of the information about my friends store on FB is practically irretrievable when it comes to my devices. Wouldn't it be great to click 'export' and have all the data merged into my Address Book on my Mac, and synchronized to my Google accounts? Nearly all other contact-storing services from other companies allow for this functionality, get with the ball!

Of course, I'd be willing to fix it for you, just hire me.