Performance Test: Python, Perl, PHP, Java, Ruby, Bash and C

I’ve had just some time to do some performance test and compare different languages. I’ve created scripts in each language which does the following:

for 1’000’000 lines

    “line” is empty

    for 150 chars

        add char “c” to the “line”

    print out the “line”

Running the script and pipe the output to a file creates a 145MB file. And the most interesting result is the time each script took to run:

Shell$ time python createRandomFile.py --rows 1000000 --chars 150 > bigfile.py.txt
real	0m56.207s
user	0m55.348s
sys	0m0.607s
Shell$ time perl createRandomFile.pl -r 1000000 -c 150 > bigfile.pl.txt
real	0m37.742s
user	0m37.147s
sys	0m0.488s
Shell$ time php createRandomFile.php -r 1000000 -c 150 > bigfile.php.txt
real	1m9.357s
user	1m5.165s
sys	0m3.542s
Shell$ time java createRandomFile 1000000 150 > bigfile.java.txt
real	1m18.791s
user	1m0.689s
sys	0m11.133s
Shell$ time ruby createRandomFile.rb -r 1000000 -c 150 > bigfile.ruby.txt
real	1m44.118s
user	1m39.672s
sys	0m0.967s
Shell$ time ruby createRandomFile.sh 1000000 150 > bigfile.bash.txt
real	78m46.334s
user	56m30.018s
sys	3m5.280s
Shell$ time ./createRandmonFile -r 1000000 -c 150 > bigfile.c.txt
real	0m2.159s
user	0m1.339s
sys	0m0.425s

For me personally there are some unexpected new experiences:

  1. Python takes “much” longer than perl. After performance optimizing the Python script its much faster, but still slower than the perl script. Thats really sad…
  2. Not a big surprise is the fact, that the C program is the fastest. But that it is so much faster than all others is impressive.
  3. Using echo instead print in the php script gets the script one second faster.
  4. And the fact, java is one of the most slowest language of all competitors used here.
  5. Ruby is damn slow
  6. Finally, Bash IS the slowest… Damn slow! I mean, SLOOOWWW!!!

This are really interesting results!

Tagged: , , , , , , ,

Getting in contact with OpenStack

Till now, i was only able to deploy some vm’s on my MacMini Server with VMware Fusion on it. This worked oukay so far… Due to the mac mini is reaching its second birthday, it does not power vm’s very well. Also to keep the vm powered on, i need always stay logged in with the user and of course the management is only possible trough vnc directly on the server.

That was the reason for me to rent some virtual machines by rackspacecloud.com. Seriously, rackspacecloud is impressive! But keeping two or more vm’s up and running for more than a month is a really expensive playground! Moving to Amazon’s EC2 wasn’t an option too. So i decided to buy a extreme low-end cheap virutalisation capable server. After some research (Hardware should be compatible with ESXi in case of whatever) i’ve build the following server for me:

Case: Asus Vintage V8-P8H67E, Intel H67, Socket 1155, USB 3.0 (about 170$)

CPU: Intel Core i5 2500 BOX, 3.3GHz, LGA 1155, 4C/4T (about 200$)

RAM: Kingston ValueRAM, 3×4 GB, DDR3-1333, CL9 (about 60$)

Raid (optional): Adaptec RAID 2405, 4-Channel SAS/SATA, low profile (about 200$)

Additional Network: Intel PWLA8391GTBLK Pro 1000GT Gigabit Adapter PCI, Bulk (about 30$)

VLAN Gigabit Switch: HP ProCurve Switch V1810G-8 8 Port 10/100/1000 Mbps, SFP (about 110$)

Harddisk: got some at home

The Result is a Box with 100% Virtualisation Support (vPro, VT-x, VT-d, 64bit), 12GB RAM and small in form and silent too.

In the past i’ve landed several times on openstack.org during some research in automating virtualisation infrastructures. Openstack is a framework for building private clouds. Openstack promises an virtualisation ecosystem with all needed components to build a perfect world. The project looks very mature and there are a lot of partners supporting them. Openstack supports also a wide range of Hypervisors though they’r strongly recommending to use KVM for virtualistion. I will give the project a try…

 

Tagged: , , , , , ,

Safari 5.1 does not like https sites

After the update to OSX 10.7 Lion which ships Safari 5.1 i could no more open any HTTPS Sites with Safari. After googling around i found the Solution. You have just to delete the following file:

~/Library/Preferences/com.apple.security.revocation.plist

Thats all…

Since i’ve updated to 10.7 i’m faced with several bugs! Huge Bugs, which prevent me from working productive!

Tagged: , , , ,

iTunes sharing over VPN

If your are one of those people who have VPN access to their home IT infrastructure you may have wonder why iTunes sharing does not work while connected the the VPN. This is due to a limitation of VPN which does not forward any broad/multicast messages. But there is help! With the tool Network Beacon you are able to send self created beacons over the VPN connection to a remote device. I’ve tried it, and its working like a charm !

Tagged: , , , ,

So schenkt man heute

Mein Bruder heiratet demnächst. Aus diesem Grund habe ich für Ihn und seine Verlobte eine Internet Präsenz erstellt (http://corinnastefan.ch) Schnell stellt sich die Frage wie man das Thema Geschenke abhandeln könnte.

Ein paar Stunden Arbeit, und ein kleines aber feines WordPress Plugin ist geschrieben. Über eine zentrale Datenbank können Geschenke vom Brautpaar erfasst werden und die Gäste können sich bequem an Geschenken beteiligen. Sobald ich Zeit finde, werde ich die letzen Kanten und rauen Seiten des Plugins noch bearbeiten und zu wordpress.org als offizielles Plugin hochladen.

Hier ist das Plugin in Action.

Tagged: , , ,

Getting Autoupdate working on WordPress

The requirements of WordPress are at least a PHP Version of 5.2.4. If you have an older Version you may have troubles getting WordPress Autoupdate working as expected. If spend some hours in getting it working. Finally i’ve found a way… I’ve no clue if this is the only way, but it works for me and yes its a really dirty hack! So please do it, only if you really know what you’re doing!

This steps are done with the actual 3.1.3 Release of WordPress

1. Add the following Settings to your wp-config.php and be sure you’ve removed all other entries beginning with: FTP_* and FS_*

define('FTP_BASE', '/home/path/to/your/site');
define('FTP_CONTENT_DIR', '/home/path/to/your/site/wp-content/');
define('FTP_PLUGIN_DIR', '/home/path/to/your/site/wp-content/plugins/');
define('FS_METHOD', 'direct');

2. Comment out line 138 to 141 in /wp-admin/includes/class-wp-upgrader.php

 if ( !empty($upgrade_files) ) {
     foreach ( $upgrade_files as $file )
          $wp_filesystem->delete($upgrade_folder . $file['name'], true);
}

To This:

/*if ( !empty($upgrade_files) ) {
     foreach ( $upgrade_files as $file )
          $wp_filesystem->delete($upgrade_folder . $file['name'], true);
}*/

3. Add the following line after line 144

$working_dir .= "dirtyhack";

This should finally look like this:

//We need a working directory
$working_dir = $upgrade_folder . basename($package, '.zip');
$working_dir .= "dirtyhack";

Yes, this really a DIRTY HACK… If you know a better way, let me know… It works for me.

If you upgrade WordPress-Core automatically all this changes are lost!

Tagged: , , , , , ,

Enabling Redmine for Receiving Mails

Today i struggled around getting Redmine pulling Mails from a remote IMAP server and creating issues with its content. Finally i’v get it working… There are several rules you should keep in mind:

  • Be carful if you have defined any mandatory additional fields for your Issues
  • If you set unknown_user=create be sure the newly created user has access to the project automatically. If he has no access, the issue will not be created
  • If you just want to pipe Mails into a Redmine project use unknown_user=accept and o_permission_check=1 and issues are getting created with the anonymous User. Works well for a simple “one-way” posting

Finally i’ve created a small bash script to run the import process all 5 minutes:

SERVER=host.domain.tld
USER=jbauer
PASS=ILike24
 
rake -f /path/to/your/Redmine/installation/Rakefile redmine:email:receive_imap RAILS_ENV="production" \
host="$SERVER" \
username="$USER" \
password="$PASS" \
move_on_success=read \
project=sandbox \
allow_override=project,tracker,category,priority,status \
unknown_user=accept \
no_permission_check=1 \
status=New \
tracker=Bug \
priority=Low
exit $?

For mor detailed information visit the Redmine Wiki.

Tagged: , , , , ,

Connect to MSSQL Server with PHP on Linux (FreeTDS)

It may be possible, that you need to connect your PHP Script to a MSSQL Datasource. Every good web-hoster should have installed some libraries to connect to MSSQL. Usually there will be the FreeTDS Library installed.
There are two steps to be done:

1. Create a connection specific freetds.conf configuration file in the location where your other PHP files are:

[mssqlserver]
	host = 1.2.3.4
	port = 1433
	tds version = 8.0 // MSSQL 2008
	#tds version = 4.2 // older MSSQL Servers

2. You can use this connection information from your PHP script:

// Older FreeTDS installations need the FREETDSCONF Environment variable
putenv('FREETDSCONF=/path/to/freetds.conf');
// Current release of FreeTDS uses the FREETDS environment variable. So we set both to be sure
putenv('FREETDS=/path/to/freetds.conf');
$mssql = mssql_connect('mssqlserver' , 'user', 'password');
mssql_select_db('myDb',$mssql);
Tagged: , , ,

Redmine and GMail SMTP Server

It’s kind of tricky to configure redmine to send mails over GMail to project participants. The following configurations works very well for sourceTube.net. Tested with the actual Redmine Version 1.1.2 and ActionMailer 2.3.5.

Be careful editing the file. Do not use tabs, just spaces!

Just put the following in config/email.yml

production:
  delivery_method: :smtp
  smtp_settings:
    tls: true
    address: "smtp.gmail.com"
    port: 587
    domain: "domain.tld"
    authentication: :plain
    user_name: "MyEmailAddress@domain.tld"
    password: "ThisIs$ecret"
    enable_starttls_auto: true
Tagged: , , , ,

Bad UIImagePickerController

It took me more than 2 hours to fix this “Memory warning” issue with the UIImagePickerController. My Application worked very well in the simulator. On the Phone i got this Memory warning every time i took a picture with the camera. The picker returned an UIImage = nil. This is my code:

-(void)viewDidLoad 
{
     self.imgPicker = [[UIImagePickerController alloc] init]; 
     self.imgPicker.allowsImageEditing = YES;
     self.imgPicker.delegate = self; 
     self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
 
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
     dispimage = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
     [picker dismissModalViewControllerAnimated:YES]; 
}
 
-(IBAction)open
{
    if(self.imgPicker == nil)
    { 
         self.imgPicker = [[UIImagePickerController alloc] init]; 
         self.imgPicker.allowsImageEditing = YES;
         self.imgPicker.delegate = self; 
         self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    [self presentModalViewController:self.imagePicker animated:YES]; 
    [self.imagePicker release]; 
}
 
-(IBAction) print
{ 
      if(dispimage != nil)
      {
            imageView.image=dispimage; 
      }
};

And the solution? I’ve just to closed all open applications, which where a lot! It seems to me it is also a memory leak bug in current 4.0.x releases. Hopefully it will be fixed with the next iOS release.

So long, i’m going to bed now.

Tagged: , , , , ,
Page 1 of 512345