Do not run after misleading benchmarks

10 07 2007

I just had to find some time to write about this. This post is aimed to help anyone who feels elevated and impressed by the trendy benchmarks between programming languages and/or frameworks. Benchmarks are tools to help us judge. They have a purpose to serve. But using them to their lowest significance and publishing those results to the community does not help anybody. I’d rather say misleads the rookies. And let’s face it, there are more rookies in the industry right now than anyother time. High level MVC frameworks are starting to get in good stable shapes, enabling the developers do more with less. But the problem is doing more with knowing less is not good and neither is sustainable.

Let’s have a look at some posts that proves the point. Someone benchmarked Code Igniter, Cake PHP and Symfony in this blog. All the fuss is about, these three framework printing “Hello World”. This benchmark uses artillary to kill mosquitos, then honours and ranks the million dollar artillaries for doing that better that each others. And then (the catch) gets great appreciation too. What is the point of printing Hello World with RAD tools? Do you benchmark a sniper rifle, a rail gun and an AK-47 in an indoor fight and rank them which one is better? Aren’t they built for long range?

Some people did mention in the reaction that  a benchmarks like this should involve practical use. Like DB operations, ORM use, to find them perform what they are built to perform and compare them there. My intention is not to blame efforts. My point is, how many rookies gets distracted by these type of benchmarks? I say, many. Just read the comments. There are lot more examples. This one is at least,  amongst PHP frameworks. People are compairing cross language and cross purpose tools like that.

If you are either impressed or repelled by the arguments up to now, I suggest you to listen to this speech of brian d foy about benchmarking, given in Nordic Perl Workshop 2007 a few months ago. This is one of the most interesting speech I ever heard. He starts by saying, why you should never use benchmarking ever in your life. Well not ever, but not while your brain is off, as he later clarifies. And also advices to use profiling, which will help you more than benchmarking.

And about speed; speed is a very relative metric for judgement. It is sensible that RAD tools give away little bit of execution speed for developement speed. Symfony guys posted a good explanation in their blog to clear what is how and why. My final thoughts: there are lot of good frameworks to choose from, choose depending on your particular needs. But above all, choose with realistic expectations.

Blogged with Flock

Tags: , , , , , , , , , ,


Language war: bring it on ;)

21 05 2007

Smart rubbish :D. I am not a language racist though. I believe all language has their strengths and weaknesses. And nobody ever tried to create an ultimate language. And, Ruby is fine, but RoR has to survive after the hype dies. *cough* twitter *cough*. But having said that, a little nerdy language war is good for health of the community 😉

Someone commented in youtube:

I’m a big fan & user of ROR, but I don’t agree with you at all. This is really stupid to compare PHP & Ruby on Rails. This is not the same thing PHP is a language, Ruby on Rails is a framework. It would have been smarter from you to compare CakePHP or Symfony with ROR (or Struts, for Java).

Cheat sheets: lots of them

20 04 2007

Would you like some cheat sheets? OK, more then some? Here you go…

Simple FTP upload: with PHP and Perl

3 11 2006

Three simple code snippets for uploading files to a FTP server with PHP and Perl. I hope these three (might add more later) code entries will help someone find way in the forest. Here the goal is to upload some files on a ftp server quicly and easily.

There are two PHP versions here, one uses basic ftp methods and other does it with curl. In PHP arena curl is by far the best way to go about online file transfer, using any protocol. In Perl however, there are range of smart CPAN modules to choose from, each specializing on specific area (LWP::UserAgent, WWW::Mechanize etc.).

The Perl one uses CPAN module Net::FTP::Simple, instead of low level Net::FTP, which deals with FTP commands directly (Net::FTP::Simple uses Net::FTP behind the curtain).

PHP version1: using basic ftp methods
$ftp_server = '';
$ftp_user_name = 'user';
$ftp_user_pass = 'password';
$destination_file = '/ftpdir/myfile.txt';
$source_file = 'myfile.txt';

// Open FTP connection
$conn_id = ftp_connect($ftp_server);

// Login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// Check the connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";

// Upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// Check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";

// Close the FTP connection

PHP version2: using curl
$ftp_server = '';
$ftp_user_name = 'user';
$ftp_user_pass = 'password';
$destination_file = '/ftpdir/myfile.txt';
$source_file = 'myfile.txt';

$ch = curl_init();
$fp = fopen ($source_file, "r");

// we upload a text file
curl_setopt($ch, CURLOPT_URL,
"ftp://" . $ftp_user_name . ":" . $ftp_user_pass . "@" . $ftp_server . $destination_file);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);

// set size of the file, which isn't _mandatory_ but helps libcurl to do
// extra error checking on the upload.
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($source_file));

$error = curl_exec ($ch);
if ($error){echo "Error uploading file\n";}

curl_close ($ch);

Perl version: using Net::FTP::Simple
use strict;
use warnings;
use Net::FTP::Simple;
# Net::FTP::Simple wraps basic ftp tasks in easy to use functions

my $username = 'user';
my $password = 'password';
my $server = '';

# connect, check connection, upload files and report success or failure (if debug_ftp is true then prints the steps)
my @sent_files = Net::FTP::Simple->send_files({
username => $username,
password => $password,
server => $server,
remote_dir => '/ftpdir/',
debug_ftp => 1,
files => [ 'myfile1.txt','myfile2.xml','myfile2.csv', ],

# OPTIONAL: connect, check connection, get list of files and report success or failure (if debug_ftp is true then prints the steps)
my @remote_files = Net::FTP::Simple->list_files({
username => $username,
password => $password,
server => $server,
remote_dir => '/ftpdir/',
debug_ftp => 1,
# OPTIONAL: print list of files in ftp dir
print ("List:\n\t", join("\n\t", @remote_files), "\n") if @remote_files;
exit 0;