Comparison of Speed of LiveCode with PHP

Peter W A Wood peterwawood at gmail.com
Sun Nov 23 22:33:51 EST 2014


In a previous email Richard Gaskin, the LiveCode Community Manager, wrote "Given the role of memory and performance for scaling, if we want to see LC Server taken seriously as a professional server tool we need to identify and eliminate any significant performance difference between it and PHP.”

I thought that it would be worth spending a little time to compare the speed of LiveCode against the speed of PHP. I came up with a test based loosely on Carl Sassenrath’s Rebol Speed Script ( http://www.rebol.com/cgi-bin/blog.r?view=0506 ). I have found it a useful base for writing comparative scripts (either comparing languages on a single machine or comparing machines using a single language). It is far from perfect in a multi-tasking environment but I believe provides decent comparative data.

I have attached two scripts, speedtest.lc and speedtest.php. I’m sure that both could be improved significantly and welcome such improvements. The results of running the two scripts on my machine, LiveCode 7.0.0-rc-3 and PHP 5.5.14 are:

Schulz:LiveCodeServer peter$ ./speedtest.lc
LiveCode Speed Test Started
The CPU test took:             2851 ms
The Memory test took:       3656 ms
The File System test took:  1975 ms
LiveCode Speed Test Finished

Schulz:LiveCodeServer peter$ ./speedtest.php
PHP Speed Test Started
The CPU test took:          	3921 ms
The Memory test took:       1200 ms
The File System test took:  666 ms
PHP Speed Test Finished

So it seems the LiveCode has the edge on PHP when it comes to calculations but not on memory access or file access. 

The memory test relies on using arrays, I'm not sure if that is the best way to test memory access.

Regards

Peter

Speedtest.lc

#!livecode                   

if the platform = "MacOS" then
  set the outputLineEndings to "lf"
end if

put "LiveCode Speed Test Started" & return
    
##cpu test
put the millisecs into tStart   
repeat with i = 1 to 10000000
  put sqrt(exp(i)) into tTemp
end repeat
put the millisecs into tEnd
put "The CPU test took:        " && tEnd - tStart && "ms" & return
        
##Memory Access
put the millisecs into tStart   
repeat with i = 1 to 1000000
  put random(255) into tMem[i]
end repeat
put the millisecs into tEnd
put "The Memory test took:     " && tEnd - tStart && "ms" & return
    
##Filesystem
open file "test.tmp"
put the millisecs into tStart   
repeat with i = 1 to 100000
  write "This is a test of the write speed" && random(255) to file "test.tmp"
  read from file "test.tmp" for 1 line
end repeat
put the millisecs into tEnd
put "The File System test took:" && tEnd - tStart && "ms" & return
delete file "test.tmp"

##Finish
put "LiveCode Speed Test Finished" & return

Speedtest.php

#!/usr/bin/php

<?php   

print "PHP Speed Test Started\n";

//cpu test
$start = microtime(true);
for( $i = 0; $i < 10000000; $i++ ) {
  $temp = sqrt(exp($i));
}
$end = microtime(true);
$time = ($end - $start) * 1000 + 0.5;
printf("The CPU test took:         %5.0f ms\n", $time);
        
//Memory Access
$start = microtime(true);
for( $i = 0; $i < 1000000; $i++ ) {
  $mem[i] = rand(0, 255);
}
$end = microtime(true);
$time = ($end - $start) * 1000 + 0.5;
printf("The Memory test took:      %5.0f ms\n", $time);

//Filesystem
$file = fopen("test.tmp", "w+");
$start = microtime(true);
for( $i = 0; $i < 100000; $i++ ) {
  rewind($file);
  fwrite($file, "This is a test of the write speed".rand(0,255));
  fread($file, 34);
}
$end = microtime(true);
$time = ($end - $start) * 1000 + 0.5;
printf("The File System test took: %5.0f ms\n", $time);
unlink("test.tmp");

//Finish
print "PHP Speed Test Finished\n";

?>






More information about the use-livecode mailing list