php 百分比用图形显示,在PHP中使用百分比

if (rand(1, 100) <= 20){

// show page 1

} else {

// show page 2

}

某些测试和比较:

Results for round 0

Method1 redirect rate: 0.200302%

Method2 redirect rate: 0.200318%

Results for round 1

Method1 redirect rate: 0.199277%

Method2 redirect rate: 0.199479%

Results for round 2

Method1 redirect rate: 0.200262%

Method2 redirect rate: 0.19995%

Results for round 3

Method1 redirect rate: 0.200254%

Method2 redirect rate: 0.200315%

Results for round 4

Method1 redirect rate: 0.199943%

Method2 redirect rate: 0.19977%

Results for round 5

Method1 redirect rate: 0.20006%

Method2 redirect rate: 0.20024%

Summary:

Method1 deviation: -9.7999999999931E-5

Method2 deviation: -7.1999999999905E-5

和代码为测试:

function method1(){

return (rand(1,5) % 5 == 0)?true:false;

}

function method2(){

return (rand(1,100) <= 20)?true:false;

}

$iterations = 1000000;

for ($j = 0; $j <= 5; $j++){

$m1 = 0;

$m2 = 0;

for ($i = 0; $i < $iterations; $i++){

if (method1()){

$m1++;

}

if (method2()){

$m2++;

}

}

$dx1 = $m1/$iterations;

$dx2 = $m2/$iterations;

$dev1 += 0.2 - $dx1;

$dev2 += 0.2 - $dx2;

echo "Results for round $j\n";

echo "Method1 redirect rate: " . $dx1 . "%\n";

echo "Method2 redirect rate: " . $dx2 . "%\n";

}

echo "Summary:\n";

echo "Method1 deviation: $dev1\n";

echo "Method2 deviation: $dev2\n";

另外

$ /usr/bin/time -l php -q test.php

5.25 real 5.19 user 0.01 sys

8224768 maximum resident set size

0 average shared memory size

0 average unshared data size

0 average unshared stack size

2090 page reclaims

0 page faults

0 swaps

17 block input operations

4 block output operations

0 messages sent

0 messages received

0 signals received

17 voluntary context switches

592 involuntary context switches

$ /usr/bin/time -l php -q test.php

4.75 real 4.73 user 0.01 sys

8216576 maximum resident set size

0 average shared memory size

0 average unshared data size

0 average unshared stack size

2088 page reclaims

0 page faults

0 swaps

0 block input operations

0 block output operations

0 messages sent

0 messages received

0 signals received

0 voluntary context switches

100 involuntary context switches

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值