If your app is going to communicate with your server while it is running, you’ve probably wondered how much your app will slow down when it has to wait for the server.
In this blog post, we’re going to make a program to test this. We’ll construct a little program which sends data to the server as many times as it can. The server will record the information in a log file. Here is what our app will do:
Do Until SysInfo(10) > limit req=Ajax("ajaxLog.php/?myText=" + Now) counter=counter+1 Loop
SysInfo(10) is the current time in milliseconds. Limit is the time we want run to. You can run this test for up to about 5 seconds: after that, the system will think you are in a endless loop and shut you down.
On the server side, we need a PHP script to get the messages and write them out to disk. Here’s the code:
<?php // read and append to file $myFile = "AjaxLog/log.txt"; $f = fopen($myFile, 'a') or die("can't open file"); fwrite($f, $_GET['myText'] . Chr(13) . Chr(10)); fclose($f); ?>
Now, let’s run it on a few different devices and see how many accesses we can do per second:
Desktop (Ethernet) | 2745.0 |
iPhone 4 (WiFi) | 10.5 |
iPhone (3G) | 2.5 |
Nexus S (WiFi) | 5.0 |
Kindle Fire (WiFi) | 9.0 |
It’s obvious that the speed that really depends on what kind of connection you have to the web. A hard wire to your router gets the best time. WiFi is much slower, and 3G is slower again. No real surprise here.
The speeds shown here probably are not what you will see if you run the same test. There are a number of factors that will affect the speed:
- Type of data connection
- Load on the network
- Number of hops the data has to make to get to the server
- Load on the server
(You can try this sample yourself – it is called AjaxLog in the Samples folder.)