Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Benchmark_on_iOS

3925ee6eaa41031bac799de0f4f528ec?s=47 to4iki
October 08, 2016

 Benchmark_on_iOS

3925ee6eaa41031bac799de0f4f528ec?s=128

to4iki

October 08, 2016
Tweet

Transcript

  1. Benchmark on iOS shinjyuku.lt #2 @to4iki

  2. ୭ʁ • @to4iki • GANMA!ͱ͍͏ອը഑৴ͷαʔϏεΛ࡞ͬͯ ͍·͢

  3. Agenda • ՝୊ • Benchmarkͱ͸ • BenchmarkΛͱΔ

  4. ՝୊ • iOSΞϓϦʹ͓͍ͯϖʔδද͕ࣔ஗͍ͷΛߴ଎ Խ͍ͨ͠

  5. ո͍͠ͱ͜Ζ͸୔ࢁ • HTTP௨৴ • JSONͷσγϦΞϥΠζ • ඳը(UITableView etc..) • ը૾ؔ࿈

    • etc…
  6. ݪҼΛಛఆ͢ΔͨΊͷࡐྉ͕ ඞཁ

  7. ܭଌ͠Α͏

  8. None
  9. https://developer.apple.com/jp/documentation/ToolsLanguages/Conceptual/ Xcode_Overview/Debugging/MeasuringPerformance.html

  10. XCTest#mesure

  11. https://developer.apple.com/reference/xctest/xctestcase/1496290-measure

  12. ࢖͍ॴ • ͬ͘͟Γͱͨ͠ಛఆͩͱInstrument͸ߴػೳ ͗͢Δ => ࡉཻ͔͍౓Ͱݟ͍ͨࡍʹ͸༗ޮ • XCTest#mesure͸test࣮ߦͷ࣌ͷΈ͔͠ܭଌ Ͱ͖ͳ͍

  13. ΑΓ”ࡶ”ʹݪҼΛಛఆ͍ͨ͠

  14. Benchmark

  15. Benchmark • ൺֱͷͨΊʹ༻͍Δࢦඪ • ਫ४΍ج४ • ଌྔʹ͓͍ͯ… • ௨ৗͰ͸ಈ͔ͳ͍ҐஔΛϕϯν”ϚʔΫ”ϙΠϯ τʹఆΊͦΕΛج४ͱͯ͠ݐ෺ɺߏ଄෺ͷҐஔ

    ΛܾΊΔ
  16. Benchmark(Programming) • ϥΠϒϥϦͷબఆɺγεςϜߏ੒ͷܾఆͳͲʹ౰ͨͬͯɺ୭΋͕ೲಘ Ͱ͖٬؍తͳ൑அΛԼ͢͜ͱΛՄೳͱ͢ΔࠜڌͱͳΔఆྔతͳࢦඪ • ಛఆͷॲཧΛऴ͑Δ·Ͱʹ͔͔Δ࣌ؒ • ಛఆͷ࣌ؒ಺ʹॲཧͰ͖ͨճ਺ • ϝϞϦফඅྔͷਪҠ

    • σΟεΫΞΫηεͷස౓ • etc…
  17. func measure(f: () -> Void) { let start = CACurrentMediaTime()

    f() let end = CACurrentMediaTime() print("Time: \(end - start)") } // exc measure { aswesome() }
  18. func measure<A>(f: () -> A) -> A { defer {

    print("Time: \(end - start)") } let start = CACurrentMediaTime() let result = f() let end = CACurrentMediaTime() return result } // exc let result = measure { aswesome() }
  19. ࠷௿ݶͷࢦඪ • nճ࣮ߦͨ͠৔߹ͷ • ฏۉ࣮ߦ࣌ؒ • ඪ४ภࠩ(͹Β͖ͭ)

  20. to4iki/Benchmark https://github.com/to4iki/Benchmark

  21. None
  22. to4iki/Benchmark • Inspired by Ruby Benchmark Module • Swift3.0੡ •

    XCTest#measureʹد͍ͤͯΔ • ؆қతͳϝτϦΫεܭଌΛߦ͏
  23. let time = Benchmark.realTime(label: "awesome: ") { sleep(3) } print(time)

    // awesome: 0.030s let metrics = Benchmark.measure(label: "[awesome]") { awesome() } print(metrics) // [awesome] // average: 0.030s // STDDEV: 4%
  24. let n = 100000 Benchmark.bm(labels: ["total: ", "ave: "]) {

    (r: Benchmark.Report) -> [TimeInterval] in let ex1 = r.time(label: "for: ") { for i in 1...n { String(i) } } let ex2 = r.time(label: "forEach: ") { (1...n).forEach({ String($0) }) } let total = ex1.elapsed + ex2.elapsed let ave = total / 2 return [total, ave] } // for: 0.027s // forEach: 0.037s // total: 0.064s // ave: 0.032s
  25. ࢖ͬͯΈͨ • ࣮ϓϩμΫτͷܭଌʹ࢖༻ • ·ͩ·ͩ࢖͍ʹ͍͘఺΋ൃݟ

  26. ໰୊఺ • ϓϩμΫγϣϯίʔυʹϏδωεཁ݅Ҏ֎ͷ ίʔυΛຒΊࠐΈͨ͘ͳ͍ͷͰ • AOPͰܭଌ༻ͷϩάग़ྗΛ෼཭͍ͨ͠ (http://qiita.com/xaatw0/items/ 5876afa418d4b6467e4e) • ଌఆͷ։࢝ͱऴྃͷ໌ࣔతͳίϯτϩʔϧ

  27. ·ͱΊ • ·ͣ”ࡶ”ʹ”ܭଌ”(ݱঢ়Λ೺Ѳ͢ΔͨΊ) • ͦͷ͋ͱʹৄࡉΛ֬ೝ • ϕϯνϚʔΫΛऔΔࡍʹͲͷ؍఺ʹண໨͢Δ ͔Λ͸͖ͬΓͤ͞Α͏

  28. Any Questions?

  29. (͓·͚) Ͳ͏͍ͬͨνϡʔχϯάΛߦ͔ͬͨ • σʔλؒ௨৴ʹMessagePackΛ࢖༻ͯ͠Έͨ • ίετʹରͯ͠ϖΠ͠ͳ͍ͷͰෆ࠾༻ • ࠶ඳըΛݮΒ͢Α͏ʹλΠϛϯάௐ੔ • ߴ͞ܭࢉ΍ճస࣌ͷϩδοΫΛվम

    • ஍ಓʹίπίπͱϨΠΞ΢τఆٛݟ௚͠