简体   繁体   中英

Spreadsheet_Excel_Reader public api vs direct access speed difference (PHP)

Both of the following are in nested loops, the first one takes 178 seconds to run through the loop, while the second one takes 1.25 seconds. Internally they are both doing the same thing.

$data->sheets[0]['cells'][$i][$j+1];

vs

$data->val($i, $j+1);

The val function does (along with other checks, does the following):

return $this->sheets[$sheet]['cells'][$row][$col];

What could be causing this discrepancy?

Methods calls do have more overhead than property accesses, but I wouldn't think it would cause a discrepancy this substantial. I would suggest profiling both cases with something like Xdebug to see where the bottleneck is. http://xdebug.org/docs/profiler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM