Your SlideShare is downloading. ×
PHP conference 2013 ja report
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

PHP conference 2013 ja report

269
views

Published on

PHPカンファレンス2013のセッション、「PHPコアから読み解く、定石の嘘ホント」を参考にまとめたスライドです。

PHPカンファレンス2013のセッション、「PHPコアから読み解く、定石の嘘ホント」を参考にまとめたスライドです。

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
269
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 「PHPコアから読み解く 定石の嘘ホント」より @akirakoyasu PHP CONFERENCE 2013 9/14 Sat. 大田区産業プラザPiO
  • 2. Copyright © 2013 Akira Koyasu. Some rights reserved. Theory 2 定石、定跡(じょうせき)とは、アブストラクトゲームに おける用語である。お互いが最善と考えられる手を行った 場合の一連の手のこと。チェスでは、「セオリー」とも。 石を用いる囲碁、オセロ、連珠などでは「定石」が、駒を 用いる将棋、チェスなどでは「定跡」が用いられる。 - ja.wikipedia.org photo#1
  • 3. Copyright © 2013 Akira Koyasu. Some rights reserved. 3 Rule 2つのコードを見せます どちらが速く動くか考えてください 考える時間は10秒 相談しないで!
  • 4. Copyright © 2013 Akira Koyasu. Some rights reserved. Execution Time 4 $time1 = microtime(true); // test code loop (100000 times) $time2 = microtime(true); printf("time: %f sn", ($time2 - $time1));
  • 5. Copyright © 2013 Akira Koyasu. Some rights reserved. opcode 5 $ sudo pecl install channel://pecl.php.net/vld-0.12.0 $ php -dvld.active=1 -dvld.execute=0 test.php Extension vld
  • 6. Copyright © 2013 Akira Koyasu. Some rights reserved. PHP runtime 6 .php.php.php Parser Compiler Virtual Machine
  • 7. Copyright © 2013 Akira Koyasu. Some rights reserved. PHP runtime 6 .php.php.php Parser Compiler Virtual Machine AST 構文解析
  • 8. Copyright © 2013 Akira Koyasu. Some rights reserved. PHP runtime 6 .php.php.php Parser Compiler Virtual Machineopcode AST 構文解析 コンパイル
  • 9. Copyright © 2013 Akira Koyasu. Some rights reserved. PHP runtime 6 .php.php.php Parser Compiler Virtual Machineopcode AST 構文解析 コンパイル 実行
  • 10. Copyright © 2013 Akira Koyasu. Some rights reserved. 7 Ready?
  • 11. Copyright © 2013 Akira Koyasu. Some rights reserved. Loop 8 A B
  • 12. Copyright © 2013 Akira Koyasu. Some rights reserved. Loop 8 $c = sizeof($arr); for ($i = 0; $i < $c; $i++) { $t = $arr[$i]; } foreach ($arr as $val) { $t = $val; } A B ただし、 とする$arr = range(0, 100);
  • 13. Copyright © 2013 Akira Koyasu. Some rights reserved. Loop 8 $c = sizeof($arr); for ($i = 0; $i < $c; $i++) { $t = $arr[$i]; } foreach ($arr as $val) { $t = $val; } A B ただし、 とする$arr = range(0, 100);
  • 14. Copyright © 2013 Akira Koyasu. Some rights reserved. foreach ($arr as $val) { $t = $val; } $c = sizeof($arr); for ($i = 0; $i < $c; $i++) { $t = $arr[$i]; } FE_RESET FE_FETCH DO_FCALL 'sizeof' IS_SMALLER POST_INC FETCH_DIM_R Answer 9 A B
  • 15. Copyright © 2013 Akira Koyasu. Some rights reserved. foreach ($arr as $val) { $t = $val; } $c = sizeof($arr); for ($i = 0; $i < $c; $i++) { $t = $arr[$i]; } time: 0.683817 s FE_RESET FE_FETCH time: 1.043019 s DO_FCALL 'sizeof' IS_SMALLER POST_INC FETCH_DIM_R Answer 9 A B
  • 16. Copyright © 2013 Akira Koyasu. Some rights reserved. foreach ($arr as $val) { $t = $val; } $c = sizeof($arr); for ($i = 0; $i < $c; $i++) { $t = $arr[$i]; } time: 0.683817 s FE_RESET FE_FETCH time: 1.043019 s DO_FCALL 'sizeof' IS_SMALLER POST_INC FETCH_DIM_R Answer 9 A B
  • 17. Copyright © 2013 Akira Koyasu. Some rights reserved. foreach ($arr as $val) { $t = $val; } $c = sizeof($arr); for ($i = 0; $i < $c; $i++) { $t = $arr[$i]; } time: 0.683817 s FE_RESET FE_FETCHtime: 1.043019 s DO_FCALL 'sizeof' IS_SMALLER POST_INC FETCH_DIM_R Answer 9 A B
  • 18. Copyright © 2013 Akira Koyasu. Some rights reserved. Elements 10 A B
  • 19. Copyright © 2013 Akira Koyasu. Some rights reserved. Elements 10 if (count($arr) > 0) { ; } if (!empty($arr)) { ; } $arr = array();ただし、 とする A B
  • 20. Copyright © 2013 Akira Koyasu. Some rights reserved. Elements 10 if (count($arr) > 0) { ; } if (!empty($arr)) { ; } $arr = array();ただし、 とする A B
  • 21. Copyright © 2013 Akira Koyasu. Some rights reserved. Answer 11 if (count($arr) > 0) { ; } if (!empty($arr)) { ; } A B DO_FCALL 'count' IS_SMALLER ISSET_ISEMPTY_VAR BOOL_NOT
  • 22. Copyright © 2013 Akira Koyasu. Some rights reserved. Answer 11 if (count($arr) > 0) { ; } if (!empty($arr)) { ; } A B time: 0.026228 s time: 0.008356 s DO_FCALL 'count' IS_SMALLER ISSET_ISEMPTY_VAR BOOL_NOT
  • 23. Copyright © 2013 Akira Koyasu. Some rights reserved. Answer 11 if (count($arr) > 0) { ; } if (!empty($arr)) { ; } A B time: 0.026228 s time: 0.008356 s DO_FCALL 'count' IS_SMALLER ISSET_ISEMPTY_VAR BOOL_NOT
  • 24. Copyright © 2013 Akira Koyasu. Some rights reserved. Answer 11 if (count($arr) > 0) { ; } if (!empty($arr)) { ; } A B time: 0.026228 s time: 0.008356 s DO_FCALL 'count' IS_SMALLER ISSET_ISEMPTY_VAR BOOL_NOT
  • 25. Copyright © 2013 Akira Koyasu. Some rights reserved. 12 Points 測ってみる 調べてみる 考えてみる
  • 26. Copyright © 2013 Akira Koyasu. Some rights reserved. 13 Any Questions?
  • 27. Copyright © 2013 Akira Koyasu. Some rights reserved. Notes This work is licensed under the Creative Commons Attribution- NonCommercial 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/. 14 photo#1: http://www.flickr.com/photos/sbl/1617711/ Thank you very much, Feedback Welcome! http://twitter.com/akirakoyasu http://fb.me/akirakoyasu http://www.akirakoyasu.net