php conference 2013 ja report

27
PHPコアから読み解く 定石の嘘ホント」より akirakoyasu PHP CONFERENCE 2013 9/14 Sat. 大田区産業プラザPiO

Upload: akira-koyasu

Post on 21-May-2015

295 views

Category:

Technology


0 download

DESCRIPTION

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

TRANSCRIPT

Page 1: PHP conference 2013 ja report

「PHPコアから読み解く 定石の嘘ホント」より

@akirakoyasu

PHP CONFERENCE 2013 9/14 Sat. 大田区産業プラザPiO

Page 2: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

Theory

2

定石、定跡(じょうせき)とは、アブストラクトゲームにおける用語である。お互いが最善と考えられる手を行った場合の一連の手のこと。チェスでは、「セオリー」とも。石を用いる囲碁、オセロ、連珠などでは「定石」が、駒を用いる将棋、チェスなどでは「定跡」が用いられる。

- ja.wikipedia.org

photo#1

Page 3: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved. 3

Rule

2つのコードを見せます

どちらが速く動くか考えてください

考える時間は10秒

相談しないで!

Page 4: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

Execution Time

4

$time1 = microtime(true);

// test code loop (100000 times)

$time2 = microtime(true);

printf("time: %f s\n", ($time2 - $time1));

Page 5: PHP conference 2013 ja report

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

Page 6: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

PHP runtime

6

.php.php.php Parser

Compiler

Virtual Machine

Page 7: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

PHP runtime

6

.php.php.php Parser

Compiler

Virtual Machine

AST

構文解析

Page 8: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

PHP runtime

6

.php.php.php Parser

Compiler

Virtual Machineopcode

AST

構文解析

コンパイル

Page 9: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

PHP runtime

6

.php.php.php Parser

Compiler

Virtual Machineopcode

AST

構文解析

コンパイル

実行

Page 10: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved. 7

Ready?

Page 11: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

Loop

8

A B

Page 12: PHP conference 2013 ja report

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);

Page 13: PHP conference 2013 ja report

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);

Page 14: PHP conference 2013 ja report

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_RESETFE_FETCH

DO_FCALL 'sizeof'IS_SMALLERPOST_INCFETCH_DIM_R

Answer

9

A B

Page 15: PHP conference 2013 ja report

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_RESETFE_FETCH

time: 1.043019 s

DO_FCALL 'sizeof'IS_SMALLERPOST_INCFETCH_DIM_R

Answer

9

A B

Page 16: PHP conference 2013 ja report

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_RESETFE_FETCH

time: 1.043019 s

DO_FCALL 'sizeof'IS_SMALLERPOST_INCFETCH_DIM_R

Answer

9

A B

Page 17: PHP conference 2013 ja report

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 sFE_RESETFE_FETCHtime: 1.043019 s

DO_FCALL 'sizeof'IS_SMALLERPOST_INCFETCH_DIM_R

Answer

9

A B

Page 18: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

Elements

10

A B

Page 19: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

Elements

10

if (count($arr) > 0) { ;}

if (!empty($arr)) { ;}

$arr = array();ただし、 とする

A B

Page 20: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved.

Elements

10

if (count($arr) > 0) { ;}

if (!empty($arr)) { ;}

$arr = array();ただし、 とする

A B

Page 21: PHP conference 2013 ja report

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_VARBOOL_NOT

Page 22: PHP conference 2013 ja report

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_VARBOOL_NOT

Page 23: PHP conference 2013 ja report

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_VARBOOL_NOT

Page 24: PHP conference 2013 ja report

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 sDO_FCALL 'count'IS_SMALLER

ISSET_ISEMPTY_VARBOOL_NOT

Page 25: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved. 12

Points

測ってみる 調べてみる

考えてみる

Page 26: PHP conference 2013 ja report

Copyright © 2013 Akira Koyasu. Some rights reserved. 13

Any Questions?

Page 27: PHP conference 2013 ja report

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/akirakoyasuhttp://fb.me/akirakoyasu

http://www.akirakoyasu.net