Thought & Theory

In Theory

You are currently browsing the archives for the Programming category.

Archive for the 'Programming' Category

Akelos does PHP and Ruby on Rails all over again

Akelos = PHP + RoR ...again

Why haven’t I heard of Akelos? I suppose I should be thankful for finally getting out of the PHP community but its always a good idea to keep track of what’s out there. How are software developers supposed to “use the best tool for the job” if their toolbelt is only 3 tools deep?

Watching an Akelos screencast is not all that different from watching a rails screencast as most of the terminology is the same: MVC, generators, scaffolding, migrations, etc. At first I was a little concerned that Akelos was ripping off Ruby on Rails (again) but their homepage does state that akelos is a “port of Ruby on Rails” and that it’d be useful for Ruby on Rails developers who need to code in PHP. After reading that I began to think that a PHP port of rails may not be such a bad thing. It would definitely flatten out the learning curve that’s presented in learning other PHP frameworks like CakePHP, CodeIgniter, or Symphony.

Speaking of “ripping off”, that community logo looks awfully familiar:

Ubuntu inspired artwork on akelos site

So, next time you’ve got a PHP project on your hands, I suggest that you check out Akelos, it couldn’t hurt.

Holy Performance! How to make python string concatenation fast

I hear that operator based string concatenation (”hello” + ” world”) is often the newbie’s approach to combining strings in Python but it’s not every day that I have to create huge strings from 35MB text files. Why am I creating huge strings? Well, one insert is better than 30,000!

Originally, my script executed one mysql INSERT per line which was approximately 30,000 INSERTs; it took about 10 minutes to run. One of the negative things about an ORM is that they make it terribly easy to write inefficient code. It’s quite handy to create one object per line of data and play with it, quickly build relations, and save it without having to write any ugly SQL but because the ORM essentially hides the fact that you’re working with a database, sometimes your pretty object-oriented code sends exhaustive messages to your database.

So I refactored my code, and now I have one massive INSERT statement which gets sent to the database. My early tests on small datasets looked good but when I tested my code with the full dataset, it never finished. After commenting out different sections of code, I found the nasty beast which was slowing me down: string concatenation.

Thanks to a survey of different methods for string concatenation I changed my code again and finally got my 10 minute script to run in 90 seconds.

According to the survey, the string method `join` is very fast and using it with a list comprehension makes the total operation even faster. Next time you’re combining strings, remember:

' '.join([a for a in ['a','join','will','make','it','faster!']])