Open omatrycy opened 5 years ago
I can try to use hash directly. Second, zephir_array_update_multi is retrieved only once according to the context, not every update.
My test result: PHP
$ time php ../../test2.php
real 0m0.115s
user 0m0.095s
sys 0m0.020s
zephir
$ time php ../../test.php
real 0m0.164s
user 0m0.140s
sys 0m0.024s
After optimization
time php ../../test.php
real 0m0.089s
user 0m0.049s
sys 0m0.040s
@sergeyklay Please take look if you can add reference type, and convert as follows:
public function generate(int size) -> array
{
var output = [];
var i = 0;
var j = 0;
for i in range (0, size) {
var arr;
let output[i] = [];
let arr = &output[i]; // <-- reference
for j in range(0, size) {
let arr[j] = 1;
}
}
return output;
}
to c code like this
...
zephir_array_update_zval(&output, &i, &empty_arr, PH_COPY | PH_SEPARATE);
zephir_array_fetch(&empty_arr, &output, &i, PH_NOISY|PH_READONLY, ...); // key point, use PH_READONLY, if reference type
...
zephir_array_update_zval(&empty_arr, &j, &value, PH_COPY); // key point, don't use PH_SEPARATE, if reference type
...
Great improvement!
Hello Code generated by zephir for setting multi-dimension array is very slow.
Example zep file:
Example php code used this module:
Execution time: real 0m4,693s user 0m4,658s sys 0m0,020s
Generated c code for this function
Similar code created in php
Execution time: real 0m0,178s user 0m0,156s sys 0m0,021s
For calculating time I used linux time command. PHP version : PHP 7.2.19-0ubuntu0.19.04.1 (cli) (built: Jun 4 2019 14:44:42) ( NTS ) Zephir version : 0.12.0 (with default configuration for new projects)