Laravel Collectionの計算量を調べてみた
by
Ryo Tomidokoro
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Laravel CollectionͷܭࢉྔΛௐͯΈͨ 1)1ษڧձ *OOPWBUPS+BQBO*OD ॴ྄ &OHJOFFS
Slide 2
Slide 2 text
ܭࢉྔʹ͍͓ͭͯ͞Β͍ ຊ࣌ؒతܭࢉྔΛѻ͍·͢
Slide 3
Slide 3 text
ྫ͑ϨϏϡʔ͍ͯ͠Δ࣌
Slide 4
Slide 4 text
ʮ͜ͷॲཧͦ͏ʯ ͜Εͩͱ͔Γʹ͍͘ɻ ॲཧͷ࣌ؒతΛڞ௨ࣝͰ͍͑ͨ
Slide 5
Slide 5 text
ӳޠͩͱ Time Complexity ࣌ؒෳࡶੑ ϓϩάϥϜͷॲཧʹ ͲΕ͘Β͍͕͔͔࣌ؒΔ͔Λ ֶతʹѻ͏
Slide 6
Slide 6 text
Oه๏ O(1) O(log n) O(n) O(n * log n) O(n^2) ϓϩάϥϜͷ࣌ؒతܭࢉྔΛද͢
Slide 7
Slide 7 text
Oه๏ σʔλྔ͕૿Ճͨ͠߹ͷ ॲཧ࣌ؒͷ૿Ճ͕͔Δ
Slide 8
Slide 8 text
[άϥϑҾ༻] ։ൃ৽ଔʹ๋͙ɺجຊͷΞϧΰϦζϜͱܭࢉྔ http://www.techscore.com/blog/2016/08/08/։ൃ৽ଔʹ๋͙ɺجຊͷΞϧΰϦζϜͱܭࢉྔ/ σʔλྔͱܭࢉྔ
Slide 9
Slide 9 text
ܭࢉྔͱΞϧΰϦζϜ ΞϧΰϦζϜ ܭࢉྔ όϒϧιʔτ 0 O? Ϛʔδιʔτ 0 OMPHO όΠφϦαʔν 0 MPHO ΞϧΰϦζϜʹΑͬͯܭࢉྔ͕ҟͳΔ
Slide 10
Slide 10 text
͞Βʹৄ͘͠Γ͍ͨਓ ֶΨʔϧ4 ཚΞϧΰϦζϜ 2ষͱ6ষΛಡΉ͠
Slide 11
Slide 11 text
ຊʹΔ
Slide 12
Slide 12 text
Laravel Collection֤ϝιουͷܭࢉྔ ͏ͪΐͬͱ͖Ε͍ʹ͠·͢…
Slide 13
Slide 13 text
ࡶʹ·ͱΊΔͱ • ΄ͱΜͲ O(n) • O(1) ͕9ݸ • O(n^2) Ҏ্͕8ݸ
Slide 14
Slide 14 text
ཁҙϝιου • collapse O(n^2) • crossJoin O(n^3) • diff O(n^t) • diffAssoc O(n^t) • flatMap O(n^2) • flatten O(n^2) • groupBy O(n^2) • intersect O(n^2)
Slide 15
Slide 15 text
࣮ଌͯ͠Έͨ
Slide 16
Slide 16 text
where - O(n) ॲཧ࣌ؒ(ඵ) σʔλ݅
Slide 17
Slide 17 text
count - O(1) ॲཧ࣌ؒ(ඵ) σʔλ݅
Slide 18
Slide 18 text
collapse - O(n^2) ॲཧ࣌ؒ(ඵ) σʔλ݅
Slide 19
Slide 19 text
crossJoin - O(n^3) ॲཧ࣌ؒ(ඵ) σʔλ݅
Slide 20
Slide 20 text
diff - O(n^t) ॲཧ࣌ؒ(ඵ) σʔλ݅ tfieldʹґଘ͢Δ
Slide 21
Slide 21 text
ܭࢉྔ͕͔ͬͨͱͯ͠ Կ͔ྑ͍͜ͱ͋Δͷ͔ʁ
Slide 22
Slide 22 text
Βͳ͍ͱѱ͍͜ͱ͕ى͖Δ
Slide 23
Slide 23 text
࣮ࡍʹ͔͋ͬͨ͠Εͳ͍ ܭࢉྔ͕ʹͳͬͨίʔυྫ ※࣮Λݩʹͨ͠ϑΟΫγϣϯͰ͢
Slide 24
Slide 24 text
શ݅औಘ ϖʔδϯάͷͨΊʹ શ݅ϧʔϓͰճ͢ ྫ1
Slide 25
Slide 25 text
શ݅औಘ ϖʔδϯάͷͨΊʹ શ݅ϧʔϓͰճ͢ ϖʔδͷޙʹߦ͚ߦ͘΄Ͳ ϧʔϓ͕ճͬͯ͘ͳΔ O(n) ྫ1
Slide 26
Slide 26 text
߹Θٕͤ O(n^2) O(n)ΛೖΕࢠʹ͢ΕύϫʔΞοϓ ྫ2 ୈ1ϧʔϓͰશ݅ճ͢ O(n) ୈ2ϧʔϓશ݅ճ͢ O(n)
Slide 27
Slide 27 text
ୈҰҾ࠷େͰඦ݅ఔ͕ͩͬͨ ୈೋҾͷσʔλ͕͍ͯͬͯ͠… ྫ2 ୈ1ϧʔϓͰશ݅ճ͢ O(n) ୈ2ϧʔϓશ݅ճ͢ O(n)
Slide 28
Slide 28 text
ྫ2ͷΞϧΰϦζϜΛ࡞ͬͯ ࣮ଌͯ͠ΈΔ
Slide 29
Slide 29 text
σʔλྔʹΑΔੑೳͷྼԽ ॲཧ࣌ؒ(ඵ) σʔλ݅ (ୈ1,2 Ҿಉ͡)
Slide 30
Slide 30 text
ͪΌΜͱO(n^2)ͷ άϥϑʹͳͬͨ
Slide 31
Slide 31 text
ࣄલʹݕͰ͖ͳ͍͔ʁ
Slide 32
Slide 32 text
࣮ྫ̍ɾ̎ͷίʔυ ୯ମςετ -> ௨ա ड͚ೖΕςετ -> ௨ա ௨աͯ͠͠·͍ͬͯͨ…
Slide 33
Slide 33 text
ෛՙςετ ίʔυϨϏϡʔ ࣄલݕग़Մೳͳࡆ
Slide 34
Slide 34 text
ෛՙςετ σʔλྔ͕ലେʹͳΔ͜ͱ͕ Θ͔͍ͬͯΔϓϩμΫτߦ͍ͬͯΔɻ ௨ৗͷϓϩμΫτͩͱ ͋Μ·ΓͬͯΔͷݟͨ͜ͱແ͍ɻ
Slide 35
Slide 35 text
ίʔυϨϏϡʔ ϨϏϡΞʔͷεΩϧܦݧʹґଘ ࣄલʹܭࢉྔʹ͍ͭͯ νʔϜͰษڧձͱ͔ͯ͠Ε ࢦఠˍमਖ਼؆୯ͩͱࢥ͏
Slide 36
Slide 36 text
ࢹπʔϧͰɺॲཧ࣌ؒͷϝτϦΫεΛݟͯ ཧ٧ΊͰॲཧ࣌ؒͷ͍෦ΛಛఆͰ͖Ε ·͋ɺٴୈͩͱࢥ͏ɻ ࠷ѱݟಀͯ͠
Slide 37
Slide 37 text
͓·͚
Slide 38
Slide 38 text
ܭࢉྔ͕Ұྎવ
Slide 39
Slide 39 text
σʔλͷू·ΓΛѻ͏ϓϩάϥϜ ܭࢉྔ͕໌ࣔ͞Ε͍ͯΔͱ͋Γ͕͍ͨ
Slide 40
Slide 40 text
͓͠·͍