일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 디버그
- X라소프트
- 델코리아
- ENA
- 어도비
- aws
- 팬마음
- xps15 9550
- xps
- Codeigniter
- 포토샵 고해상도
- 일러스트
- 네오커머스
- 디-버그
- 월회고
- 고해상도
- X보이스
- ami
- XPS15
- Dell
- 일러스트 고해상도
- php
- codeigniter3
- SENTRY
- 개발기록
- laravel
- monolog
- 국가번호목록 #전화번호국가코드 #퇴근을원합니다
- 포토샵
- Today
- Total
Good Day
[PHP7] REQUEST 값 가져올때 클래스 내에 static 선언한 것과 안한 함수의 속도 비교 본문
※ 주의1: 별다른 생각 없이 개발하면서 적는 부분이므로 절대 네버 에버 절대치는 아닙니다.
※ 주의2: 올바른 테스트 방법이 아닐 수 있으므로 의견 제시해주시면 참고하겠습니다.
Fanmaum팀에서 작업하다가 엑심베이에서 뭘 덜해줬는지 Alipay가 짤리는 바람에
Alipay를 오리지널로 붙히는 작업을 하게 되었다.
이번에는 함수 내에 동적 호출?
- 환경: AWS t2.micro / nginx 1.4 / php7.0.12
- 조건:
- 작성중인 php 클래스 내에 함수 두개 생성 후 각각 10만번(100,000) 호출을 10회 진행
- 혹시 몰라서 전후로 테스트 코드 위치를 변경해서 실행했다.
- 테스트 코드 1 - Common Class 내에 함수 두개
class Common { private $request; private $db_path; public function __construct(array $config = []) { $this->request = $_REQUEST; $this->db_path = str_replace('/PG/Alipay', '/application/config/database.php', BASEPATH); } public function getPath(){ return $this->db_path; } public function getVariable($key){ return self::GetVar($key); } public function getVariableP($key){ return self::getVarP($key); } private static function GetVar($key){ if(array_key_exists($key, $_REQUEST) === TRUE){ return $_REQUEST[$key]; } return NULL; } private function getVarP($key){ if(array_key_exists($key, $_REQUEST) === TRUE){ return $_REQUEST[$key]; } return NULL; } }
- 테스트 코드 2 - 테스트 실행코드
include_once('config/common.php'); $common = new Common(); for( $j = 1; $j < 11; $j++ ){ $start_time = microtime(true); for ($i=0; $i < 100000; $i++) { $e = $common->getVariable('transaction_srl'); unset($e); } $end_time = microtime(true); $static_run = ($end_time-$start_time); $start_time = microtime(true); for ($i=0; $i < 100000; $i++) { $e = $common->getVariableP('transaction_srl'); unset($e); } $end_time = microtime(true); $dynamic_run = ($end_time-$start_time); $winner = $dynamic_run > $static_run ? 'Static 승' : 'Dynamic 승'; echo "$j 회차($winner)<br/>"; echo 'original_runtime: '.$static_run.'<br/>'; echo 'foreach_runtime: '.$dynamic_run.'<br/>'; } for( $j = 1; $j < 11; $j++ ){ $start_time = microtime(true); for ($i=0; $i < 100000; $i++) { $e = $common->getVariableP('transaction_srl'); unset($e); } $end_time = microtime(true); $dynamic_run = ($end_time-$start_time); $start_time = microtime(true); for ($i=0; $i < 100000; $i++) { $e = $common->getVariable('transaction_srl'); unset($e); } $end_time = microtime(true); $static_run = ($end_time-$start_time); $winner = $dynamic_run > $static_run ? 'Static 승' : 'Dynamic 승'; echo "$j 회차($winner)<br/>"; echo 'original_runtime: '.$static_run.'<br/>'; echo 'foreach_runtime: '.$dynamic_run.'<br/>'; }
1 회차(Dynamic 승)
Static_runtime: 0.016842126846313
Dynamic_runtime: 0.016291856765747
2 회차(Static 승)
Static_runtime: 0.016741037368774
Dynamic_runtime: 0.01763391494751
3 회차(Static 승)
Static_runtime: 0.016448974609375
Dynamic_runtime: 0.01692795753479
4 회차(Static 승)
Static_runtime: 0.016345024108887
Dynamic_runtime: 0.016684055328369
5 회차(Static 승)
Static_runtime: 0.016530990600586
Dynamic_runtime: 0.017148017883301
6 회차(Static 승)
Static_runtime: 0.016345977783203
Dynamic_runtime: 0.018479108810425
7 회차(Dynamic 승)
Static_runtime: 0.016433000564575
Dynamic_runtime: 0.016161918640137
8 회차(Dynamic 승)
Static_runtime: 0.016705989837646
Dynamic_runtime: 0.016093015670776
9 회차(Dynamic 승)
Static_runtime: 0.017113924026489
Dynamic_runtime: 0.016762018203735
10 회차(Dynamic 승)
Static_runtime: 0.016911029815674
Dynamic_runtime: 0.016393899917603
11 회차(Static 승)
Static_runtime: 0.016139984130859
Dynamic_runtime: 0.016768932342529
12 회차(Static 승)
Static_runtime: 0.016220092773438
Dynamic_runtime: 0.016913890838623
13 회차(Dynamic 승)
Static_runtime: 0.017113924026489
Dynamic_runtime: 0.016468048095703
14 회차(Dynamic 승)
Static_runtime: 0.017448902130127
Dynamic_runtime: 0.017354965209961
15 회차(Static 승)
Static_runtime: 0.016324996948242
Dynamic_runtime: 0.016720056533813
16 회차(Static 승)
Static_runtime: 0.016093015670776
Dynamic_runtime: 0.016548871994019
17 회차(Dynamic 승)
Static_runtime: 0.016880035400391
Dynamic_runtime: 0.016727924346924
18 회차(Dynamic 승)
Static_runtime: 0.016458988189697
Dynamic_runtime: 0.016107797622681
19 회차(Static 승)
Static_runtime: 0.019625186920166
Dynamic_runtime: 0.025451898574829
20 회차(Static 승)
Static_runtime: 0.016524076461792
Dynamic_runtime: 0.016572952270508
테스트 결과 Static 승리
후기:
이 비교는 작업하다 문득 궁금해서 해보는 솔찬히 필요 없는 비교분석이다.
그냥 꼴리는대로 쓰자.
대략 전체적으로 엎치락 뒤치락하는데,
결과적으로 보면 엇비슷하나 static이 이길때가 많다.
'개발 > PHP' 카테고리의 다른 글
[Codeigniter] Monolog를 사용해보자 (0) | 2018.05.28 |
---|---|
[Codeigniter With Sentry] Sentry 붙이기 - 1. 코어 클래스 교체버전 (0) | 2016.12.29 |
[PHP7] foreach와 while(list()=each()) 간단 성능비교 (0) | 2016.10.27 |