Friday, February 18, 2011

Ruby v. Python

I'm gonna lose 80% of my 10 readers with this.
$ uname -a
Darwin peregrine 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386
$ python --version; time (python -c "print ''.join([chr(int(x, 16)) for x in '54 59 20 66 6f 72 20 74 68 65 20 75 70 76 6f 74 65'.split()])")
Python 2.6.1
TY for the upvote

real 0m0.039s
user 0m0.014s
sys 0m0.015s
$ ruby --version; time (ruby -e "puts '54 59 20 66 6f 72 20 74 68 65 20 75 70 76 6f 74 65'.split.map{|a|a.to_i(16)}.pack('c*')")
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
TY for the upvote

real 0m0.012s
user 0m0.002s
sys 0m0.003s
$
Partially [ via reddit ]

Update: Well, my friend Chuck over at evilchuck.com pointed out that my original post is a completely pointless comparison, since both interpreters are doing practically nothing.

He is absolutely right. If this were used as a "benchmark test" it would be laughable. Well I included the time stats, so I guess I asked for it.

Here is a little test program for generating N sets of random hex strings 17 characters long and then decoding the sets one at a time.

Ruby code:Blargh:
$ time ( ruby test.rb 500 )
wnATVthnfLdBCQguVr
[ Large output elided. ]
jPgUoj1VtucFgrt7iv

real 0m0.051s
user 0m0.030s
sys 0m0.005s
$ [ With n = 5000 ]
VyiKEjdJhjMKHPRqpP
[ Larger output elided. ]
Uh3 Wsg2 HUbAAe04J

real 0m0.461s
user 0m0.293s
sys 0m0.017s
$ [ With n = 50000 ]
yKfTGOrtCJTtyWvWJk
[ Even larger output elided. ]
QkxCNYwEFVund6H8kz

real 0m3.991s
user 0m3.238s
sys 0m0.136s
$ time ( ./test.rb 100000 -q )

real 0m6.531s
user 0m6.183s
sys 0m0.114s
$ time ( ./test.rb 1000000 -q )

real 1m42.502s
user 1m17.887s
sys 0m2.240s
$
And here's a test for some python code that I hacked together that is probably really crappy but seems to do the job.

Python version:Running it from my bash shell produces:
$ time ( ./test.py 500 )
lFy 7ZGqT1Oc BT31
[ Elision. ]
fnpLoKCaYFWL9U9SE

real 0m0.089s
user 0m0.047s
sys 0m0.024s
$ time ( ./test.py 5000 )
Hqa2g4iX6Nw8Nzua5
[ Elision. ]
ofMMAG WnxUEP0RVC

real 0m0.345s
user 0m0.282s
sys 0m0.030s
$ time ( ./test.py 50000 )
kVgC4etTXn5vxrLzV
[ Elision. ]
ot8PSkiWyn1KTitXT

real 0m3.402s
user 0m2.647s
sys 0m0.108s
$ time ( ./test.py 100000 -q )

real 0m4.403s
user 0m4.241s
sys 0m0.064s
$ time ( ./test.py 1000000 -q )

real 0m43.506s
user 0m42.172s
sys 0m0.565s
Clearly, Python is much faster than Ruby for large sample sizes. At 1M, Ruby finishes in 1m43s real and 2.24s sys. Python finishes in 43.5s real and 0.565s sys.

Just for fun, I tried running the ruby code with Ruby 1.9. This isn't fair since I am not going to go to the trouble of installing Python 3.0.1, but it doesn't matter. Ruby 1.9 is significantly faster than 1.8.7, but still can't beat Python 2.6 for this particular test.
$ time ( ruby19 test.rb 1000000 -q )

real 0m49.606s
user 0m47.847s
sys 0m0.764s
$
I was curious, so I tried to isolate the decoding part of the two versions. Here's what I found:
$ ruby19 test.rb 1000000 -q
user system total real
16.750000 0.310000 17.060000 ( 17.843644)
$ ./test.py 1000000 -q
1 function calls in 14.241 CPU seconds

Ordered by: internal time, call count

ncalls tottime percall cumtime percall filename:lineno(function)
1 14.241 14.241 14.241 14.241 test.py:18(decode)
$
Looks like the decode method written in Python is executing at least 3 seconds faster.

These tests are not intended to be benchmarks of any kind. True benchmarking is a science in which I have not educated myself very well. I just wanted to get a feel for some of the differences in Python and Ruby idioms and a rough comparison of their execution time. My guess is that if anyone were to take a close look at the code used in this post, they'd be able to point out several flaws and mistakes that would affect the overall statistics.

Update 2: Thought I'd try JRuby, and...
$ time ( jruby test.rb 1000000 -q )

real 0m28.038s
user 0m29.531s
sys 0m1.310s
$
Wow.

Wednesday, February 02, 2011

Speaking of movie posters

I missed these when he posted them to his tumblr back in December, but just look at these gorgeous prints of Olly Moss' spin on Star Wars movie posters for each in the holy trilogy.


Missed this on Wired, too. Why didn't someone I follow tweet these? (Yes, I'm rolling my eyes at myself right now.)

I only just now found out about these from a rather well-done combo version linked on Reddit.

And speaking of Olly Moss, this:

New movies that...

...would be nice to see in a theater
but I live in San Antonio.


Maybe if I drove up to Austin? Ugh.Also, I really dig this poster for Love.

Monday, January 31, 2011

Adam Curtis' The Trap

Adam Curtis is a producer, writer, and documentarian. He is British, and he works for the BBC.

In 2007, Curtis produced a series of programmes called The Trap — What Happened to our Dream of Freedom for the BBC Two Television Network.

The series includes contributing interviews with a number of economists, writers, psychiatrists, philosophers, and political scientists.

These include John Nash, Friedrich von Hayek, Isaiah Berlin, Jean-Paul Sartre, Alain Enthoven, Alexander Haig, and Madsen Pirie.

The videos incorporate newsreel footage from the Cold War decades, the Reagan-Thatcher Eras, and the 1990s and 2000s. It does so to dramatic effect, mixing soundtrack music from various movies particularly, movies by John Carpenter. It also makes use of dramatic typeface in the titles of segments. One critic has even suggested that Curtis' work is "propagandist", presumably because of his employment of the dramatic typefaces and music found in his films.

The series seeks to shed some light on the sense of entrapment, ensnarement, imprisonment that many people seem to have in this day and age. The modern dilemma -- all this freedom, and yet, millions of Americans are being treated for depression. Millions are obese. Millions of people report having feelings of purposelessness. And so on. Some people attribute these feelings to a number of causes, including technology, urban over-population, widening generation gaps, divisive politics, increasing economic class disparity, etc.

According to Curtis, all of these explanations can be seen as symptoms of a greater problem -- the notion that our freedom is defined by the pursuit of our desires.

Curtis explains how out of the nuclear strategies of the cold war, along with a fundamental shift of academic psychiatry into empiricism, the notion was formed that the individual -- as modeled by the economic theories of John Nash and adapted by military strategists -- is nothing more than a self-interested autonomous desire-fulfilling machine. This notion became the pivot for a new political revolution that supplants the old methods of societal control with a sort of irrevocable auto-pilot.

He goes on to demonstrate how this model became a self-fulfilling prophesy through the feedback reinforcement of modern marketing, media, and a corporatist-warped version of democratic politics -- ultimately trapping our society in ever more rigid and stratified constraints imposed presumably without explicit intention by not only our leaders, but by our own collective decisions and actions.

It's a remarkably in-depth attempt to analyze and explain the historical context of our modern dilemma. I like this series because it has multiple facets, and ties in many seemingly separate threads in our recent history to make a somewhat coherent whole.

It explains many things, including this paper on economic class disparity by Piketty and Saez.

Our national credit ponzi scheme since 2000? Just a symptom of this sort of thinking on Ayn Rand steroids (and by that I mean to say, the Randian market stimulant/intoxicant/performance enhancer known as Alan Greenspan).

I find it interesting that in Curtis' worldview, Reaganism and Thatcherism are just outgrowths of the deeper set of perverted ideas about what actually makes up a human being.

Thursday, December 23, 2010

Amazon saves Christmas

Not that Christmas is even a big deal for me, but it seems fun to say.

This year I'm donating money to charities and foundations in the names of friends and family members because I don't believe that a rational human being can ethically do any kind of business in America anymore.

However, I am not an ideologue (okay, maybe a little bit). And I did compromise my principles to make a couple purchases. One of which was a book for my family and friends about anthropogenic climate destabilization -- in other words: humankind's ongoing and deliberate destruction of the planet's tiny layer of organic material and gases.

Those books never made it to me.

Of course, the tracking status says that they were delivered:
DateTimeLocationEvent Details
December 20, 201012:09:00 PMSan Antonio TX USDelivered
December 20, 201012:21:00 AMSan Antonio TX USOut for delivery
December 20, 201012:21:00 AMSan Antonio TX USArrival Scan
December 17, 201005:29:00 AMOklahoma City OK USDeparture Scan
December 16, 201011:22:00 PMOklahoma City OK USArrival Scan
December 16, 201007:13:00 PMTulsa OK USDeparture Scan
December 16, 201006:36:00 PMTulsa OK USShipment received by carrier
December 16, 201011:44:22 AMUSShipment has left seller facility and is in transit

That means that the UPS parcel delivery person apparently drove his truck into my gated apartment complex without dialing the apartment number at the gate. Then parked outside my apartment building. Then took my package out of the truck. Then placed the package in front of my door... and then walked away.

Meanwhile, I was just getting back to work from lunch, completely unaware that someone was stealing the package of books off the ground outside my apartment.

Should have specified that a signature was required, I guess. Duh.

But that isn't the point. The point is that UPS was paid to deliver a package to a recipient. They should be held accountable for their complete lack of care, concern or competence in getting that job done. In my opinion it is their responsibility to deliver a package to a recipient. Because otherwise, what's the fucking point?

If they bear no such responsibility, then why don't they just deliver the package to a landfill? What is the difference between a package that gets delivered to a landfill, and a package that gets abandoned on the ground at an address that may or may not be correct with nobody around to witness its delivery? Is the difference just some words recounting a particular event? That is meaningless. Unless I actually receive the parcel, the delivery is worthless. In fact, it is less than worthless, it robs me of the time that I wasted expecting a delivery when I could have spent that time ordering the parcel from an alternative source with an alternative delivery route and process.

These questions are rhetorical, but fair and reasonable.

It is clear that UPS should be held accountable for the cost of these items, and the re-shipping.

I contacted Amazon.com about this matter, and they promised to ship the order again, this time with overnight delivery -- without any cost to me. Amazon.com is amazing.

This still doesn't get UPS off the hook. It is foolish of the UPS delivery person to have refused to leave the parcel with someone in the office of my apartment complex.

Update: So I got the second package from Amazon.com. Guess who they used to send it. Yeah, that's right. So apparently the fella delivering the package this time around didn't care to make sure the package actually got into the hands of the recipient either, and he just ran off after dropping it at my door.

Oh well. It's that time of year I guess. He must have had a ton of other parcels to deliver, and he was probably completely overburdened. I would have given him a tip, but I didn't feel like running after him in the cold.

You know what? Screw you, UPS, for overloading your drivers so much that they can't even wait for someone to answer the door. UPS, you are a $42.6 billion business. Your profits have been down 28% since 2008 to (boo hoo) $2.2 billion in 2009.

You're telling me that you couldn't hire a few dozen extra part-time drivers for the holidays, at the Scrooge-wages of $8.50-$9.50? That would have been about $50,000 to hire 36 extra drivers during the month of December. You could have afforded it, and it would have covered your demand for San Antonio and balanced the workload enough so that your delivery persons could actually wait for people to answer their door before they ran off, leaving the parcel alone and unsecured.

You surely have a quick on-boarding process considering that you almost certainly have a ridiculously high employee churn -- I mean, given that you over work your part-time employees on the holidays by assigning them with routes that are too long, and with truckloads that are too full. You sure don't have enough full-time employees.

If you did have more full-time employees, then maybe you would be able to hire fewer part-time employees to fill in the gaps during the holidays. This would allow you to focus on what it is that you actually do for your customers, both senders, and recipients -- ensuring the transportation of products all over the country. But instead, all you care about is the money. Merry Christmas, UPS.

Tuesday, December 21, 2010

Ubuntu username fail

So Ubuntu is pretty easy to use most of the time. But I've installed the system probably about two dozen times now, and each time I forget that I cannot add a username with a dot without doing some somersaults.

You cannot use the Gnome users-admin control panel to add a username such as "nels.nelson". Oh no. That would be horrible.

Instead, you have to use adduser.
sudo adduser nels.nelson --force-badname
Password:
Adding user `nels.nelson’…
Adding new group `nels.nelson’ (1002).
Adding new user `nels.nelson’ (1002) with group `nels.nelson’.
Creating home directory `/home/nels.nelson’.
Copying files from `/etc/skel’
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for nels.nelson
Enter the new value, or press ENTER for the default
Full Name []: nels.nelson
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [y/N] y

Thursday, December 16, 2010

Installing Ruby 1.9.2

wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
tar -xzf ruby-1.9.2-p0.tar.gz
pushd .
cd ruby-1.9.2.p0
./configure \
--prefix=/usr/local \
--with-arch=x86_64 \
--program-suffix=19 \
--enable-shared
make
sudo make install
popd

Tuesday, December 07, 2010

Why Grails sucks

Or,
Why Grails is the worst web application framework I have ever used in my life, and I've used some pretty bad ones

Here's one reason:
Compilation error: Compilation Failed
Application context shutting down...
Application context shutdown.
Soooo sorry, but that's nothing but 100% grade-A pure American male cow manure.