使用apache ab工具进行测试了下。
ab -n100 -c10 https://you domain/
方法1:原生php函数
$str = 'my_name_is_bill';
echo implode('', array_map(function($val) {
return ucfirst($val);
}, explode('_', $str)));
测试结果
Concurrency Level: 10
Time taken for tests: 0.657 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 16700 bytes
HTML transferred: 1200 bytes
Requests per second: 152.28 [#/sec] (mean)
Time per request: 65.669 [ms] (mean)
Time per request: 6.567 [ms] (mean, across all concurrent requests)
Transfer rate: 24.83 [Kbytes/sec] received
方法2: 自己编写php代码
$str = 'my';
if ( strpos($str, '_') === false ) {
echo ucfirst($str);exit;
}
$return = '';
foreach ( explode('_', $str) as $val ) {
$return .= ucfirst($val);
}
echo $return;
测试结果
Concurrency Level: 10
Time taken for tests: 0.632 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 15700 bytes
HTML transferred: 200 bytes
Requests per second: 158.24 [#/sec] (mean)
Time per request: 63.195 [ms] (mean)
Time per request: 6.320 [ms] (mean, across all concurrent requests)
Transfer rate: 24.26 [Kbytes/sec] received