壓測環(huán)境
機(jī)器 sim08 passenger
cpu:
mem:
PHP
用的是phpbench,9k+條key普气,17種語言,一共10w+條文案
壓測結(jié)果
迭代10次,每次迭代請求1w次仅父,平均請求時(shí)間為3230ns
|---|---|---|
|revs|請求次數(shù)|10000|
|its|迭代次數(shù)|10|
|mem_peak|內(nèi)存峰值|37,521,616b|
|cpu_peak|cpu峰值|61.5%|
|best|最短時(shí)間|2.608μs|
|mean|平均時(shí)間|3.230μs|
|mode|最頻繁的時(shí)間|2.965μs|
|worst|最差時(shí)間|4.434μs|
```shell
1 subjects, 10 iterations, 10,000 revs, 0 rejects, 0 failures, 0 warnings
(best [mean mode] worst) = 2.608 [3.230 2.965] 4.434 (μs)
?T: 32.297μs μSD/r 0.532μs μRSD/r: 16.472%
suite: 1341737daa00882869b7c9270b9fbbb33683d31e, date: 2019-10-31, stime: 20:00:15
+-----------------+-------------------+--------+--------+-------+-----+-------------+---------+---------+---------+---------+---------+--------+-------+
| benchmark | subject | groups | params | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff |
+-----------------+-------------------+--------+--------+-------+-----+-------------+---------+---------+---------+---------+---------+--------+-------+
| CopyWriterBench | benchGetPlainText | | [] | 10000 | 10 | 37,521,616b | 2.608μs | 3.230μs | 2.965μs | 4.434μs | 0.532μs | 16.47% | 1.00x |
+-----------------+-------------------+--------+--------+-------+-----+-------------+---------+---------+---------+---------+---------+--------+-------+
```
- 壓測代碼 benchMark
/** * Class CopyWriterBench * @Iterations(10) * @Revs(10000) * @BeforeMethods({"init"}) * */ class CopyWriterBench { private $copyWriter; private $cases; private $keys; private $randomInts; private $langs; public function init() { $this->copyWriter = Copywriter::getCopywriterInstance(__DIR__.'/conf'); $json_string = file_get_contents(__DIR__.'/cases.json'); $this->cases = json_decode($json_string, true); $this->randomInts = array(); for( $i=0; $i<count($this->cases); $i++) { array_push($this->randomInts, random_int(0, count($this->cases))); } $this->langs = array("es_pe","es_cr","en_br","es_ar","es_pa","ts_nl","en_au","pt_br","ja_jp","es_419","zh_tw", "zh_hk","en_us","es_mx","es_co","zh_cn","es_cl"); $this->keys = array_keys($this->cases); } public function benchGetPlainText() { $aCase = 0; try { $aCase++; $randomInt = $this->randomInts[$aCase % count($this->cases)]; $this->copyWriter->getPlainText($this->cases[$this->keys[$randomInt]], $this->langs[$randomInt%count($this->langs)]); } catch (Exception $e) { trigger_error("get copy writer error".$this->cases[$randomInt]); throwException($e); } } }