您的位置 首页 php

NodeJs与PHP的benchmark

此次基准测试只是简单测算一下node与php在冒泡排序方面的时间损耗情况,基本思想是使用冒泡排序各自运算100次之后求出平均值;冒泡排序算法摘自网上,测试代码如下:

代码

JavaScript:

function sort(arr){    var n=arr.length; //获取数组的长度,即有n个数在排序    var temp=null; //定义一个临时变量,交换数据用    for(var i=0; i<n-1; i++){ //外层循环n-1次        for(var j=0; j<n-1-i; j++){ //内层每次循环n-1-i次,每次循环完,都能从剩下的数当中找出一个最大的放在n-1-i的位置            if(arr[j]>arr[j+1]){ //如果a[j]>a[j+1]则交换位置                temp=arr[j];                arr[j]=arr[j+1];                arr[j+1]=temp;            }        }    }    return arr; //返回排好序的数组}const array = [49, 38, 65, 97, 76, 13, 27,49, 38, 65, 97, 76, 13, 27];const startTime = new Date();for (let i = 0; i <= 99; i++) {    const arr = sort(array);}console.log((new Date() - startTime) / 1000  / 100);

PHP:

function bubble_sort($array){    $count = count($array);    if ($count <= 0) return false;    for ($i = 0; $i < $count; $i++) {        for ($j = $count - 1; $j > $i; $j--) {            //如果后一个元素小于前一个,则调换位置            if ($array[$j] < $array[$j - 1]) {                $tmp = $array[$j];                $array[$j] = $array[$j - 1];                $array[$j - 1] = $tmp;            }        }    }    return $array;}$array = [49, 38, 65, 97, 76, 13, 27,49, 38, 65, 97, 76, 13, 27];$startTime = microtime(true);for ($i = 0; $i <= 99; $i++) {    $arr = bubble_sort($array);}echo number_format((microtime(true) - $startTime) / 100, 10);

注意:为了测试php5并没有采用php7的强调语法类型

测试结果

如图:

PHP5.6

3c6e80c7745bb0a1d6351d6e611d25f.png

Node7.9:

49e8505cf4141c50a8c481955b03282.png

PHP7.1

2cb21e325df0f96f3a20c88b5350abb.png

结论

三次测算的结果分别是:

d2be82ee42580fce0711f10afb94433.png

测试机器

1dca21b296ed55a79f19bbed441be12.png

从本次测试的结果来看在执行速度上 PHP7.1 > PHP5.6 > Node7.9

以上就是NodeJs与PHP的benchmark的详细内容,更多请关注求知技术网其它相关文章!

文章来源:智云一二三科技

文章标题:NodeJs与PHP的benchmark

文章地址:https://www.zhihuclub.com/2745.shtml

关于作者: 智云科技

热门文章

评论已关闭

26条评论

  1. Viagra Principio Attivo [url=https://buycialikonline.com]cialis online[/url] Levitra Scheda Tecnica

  2. Although these therapies are largely effective in controlling SLE hypertension and reducing albuminuria, combination therapy i

  3. We hypothesized that a unique set of factors, including fertility concerns, would contribute to the poor tamoxifen use among premenopausal patients

  4. 2003; MacLusky et al Risk of development of hyperkalaemia; monitor serum potassium regularly

  5. The prescribing doctor should also use the checklist available to ensure that all necessary information has been provided to the patient and or carer

  6. For various reasons we are not willing to do it and we will not agree to the shipment of even one gram of uranium from Iran, he said in the interview

  7. Port insertion, then infection at port and axilla, two different antibiotics to elimnate infection

  8. Right Sublethally irradiated 650 Rad recipient mice n 5 transplanted with 1 10 6 splenocytes isolated from moribund leukemic Tet2; AE mice LeuA Valerate 10 20 mg IM q4weeks

  9. 19 The report found that the mortality rate in patients with ICU acquired hyponatremia or hypernatremia was greater than that of study patients with normal serum sodium levels, being 28 versus 16 P

  10. If you know a cheaper plumber or electrician, for example, ask your agent to use them for future work

  11. Cadherins inhibited by Wnt signaling can also act as repressors of cell division Shi et al

  12. 3 trial, the researchers randomly split the approximately 4, 500 high risk, postmenopausal women in the study into two groups

  13. No matter what Liang Zhao does or does, in the end, it is for himself We demonstrate that TAM ER binds EREs with lower affinity than E2 ER, 4 OHT ER, or ER liganded by the covalent antiestrogen tamoxifen aziridine

  14. Highly effective Optimum quality Safe to consume Accurate composition Of the baseline survey respondents n 408 732, 55

  15. ARG ANNOT, a new bioinformatic tool to discover antibiotic resistance genes in bacterial genomes

  16. The benzoquinone ring of CoQ is synthesized from the amino acid tyrosine or phenylalanine, and the tail is produced from acetyl- CoA by the mevalonate pathway through the action of tetrameric decaprenyl diphosphate synthase, encoded by the Pdss1 and Pdss2 genes О± synuclein aggregates are primary components of Lewy bodies, the defining pathological feature of PD 40

  17. SYNTHROID is not indicated for suppression of benign thyroid nodules and nontoxic diffuse goiter in iodine sufficient patients as there are no clinical benefits and overtreatment with SYNTHROID may induce hyperthyroidism see Warnings and Precautions 5 However, using transient transfection assays, all classes of antiestrogens bound to ER ОІ are potent transcriptional activators at an AP 1 site, acting as estrogen agonists rather than antagonists 9

  18. Until I was 43 years old, and diagnosed with breast cancer was the first time I canceled everything, and laid in my room for weeks You and Dick were our favorite grownup friends of mom s and dad s, we truly loved you both and used to count the days until we could visit again

网站地图