Wondering what would be quicker for a mysql open, select, and a generic output of the data:
A) C++ code compiled, an being called through exec() (or something equivalent)
or
B) Straight PHP Code.
Given that all code is equally coded in both C++ and PHP.
Did a test: this is the C++
Document Length: 100000 bytes
Concurrency Level: 2
Time taken for tests: 0.139 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 1001550 bytes
HTML transferred: 1000000 bytes
Requests per second: 71.76 [#/sec] (mean)
Time per request: 27.872 [ms] (mean)
Time per request: 13.936 [ms] (mean, across all concurrent requests)
Transfer rate: 7018.29 [Kbytes/sec] received
This is the PHP:
Concurrency Level: 2
Time taken for tests: 4.115 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 1001550 bytes
HTML transferred: 1000000 bytes
Requests per second: 2.43 [#/sec] (mean)
Time per request: 822.924 [ms] (mean)
Time per request: 411.462 [ms] (mean, across all concurrent requests)
Transfer rate: 237.71 [Kbytes/sec] received
Here are the programs (I did not include MySql code -just wanted to see if the stack creation was quicker with basic code).
C++
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
stringstream x;
//string x;
for (int i = 0; i < 100000; ++i)
{
x << "X";
}
cout << x.str();
return 0;
}
Here is the PHP:
for ($i=0; $i<100000; ++$i)
{
$x = $x . "X";
}
echo $x;
Don't know if its a fair test using stringsteam... thoughts? My thought is, C++ is going to be faster regardless of the new stack instance, and mysql connections.
Edit:
Tested with this:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
//stringstream x;
string x;
for (int i = 0; i < 100000; ++i)
{
x = x + "X";
}
cout << x;
return 0;
}
and, still quicker!
Concurrency Level: 2
Time taken for tests: 0.115 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 1740 bytes
HTML transferred: 0 bytes
Requests per second: 86.98 [#/sec] (mean)
Time per request: 22.994 [ms] (mean)
Time per request: 11.497 [ms] (mean, across all concurrent requests)
Transfer rate: 14.78 [Kbytes/sec] received
Edit:
Here is the php program that calls the C++ file
<?php
echo exec("./test");