Swift における経過時間の計測

Swift における経過時間の計測

Ab5e75d761edf0f93cd6517d9305b39d?s=128

Yuto Mizutani

March 19, 2019
Tweet

Transcript

  1. Swift ʹ͓͚Δܦա࣌ؒͷܭଌ Yuto Mizutani

  2. Yuto Mizutani • גࣜձࣾ VALU iOS ΤϯδχΞ • ΞϝϦΧͷ৺ཧֶऀͱڞಉݚڀͯ͠·͢ •

    try! Swift Ͱ΋ LT ͠·͢
  3. ৺ཧֶݚڀ༻ΞϓϦ OperantChamberApp, YutoMizutani/OperantKit

  4. ໰୊

  5. ໰୊ Start Time: 20XX/XX/XX 14:01:07 End Time: 20XX/XX/XX 14:17:47 Session:

    1 Training: Magazine Training VT value: 20000 List of events: 99: 1000808 END OF THE SESSION Responses: 0 Responses(ITI): 0 Reinforcers: 40 1,000,000 ms (1000 ඵ㲈16෼) Ͱ ऴΘͬͯཉ͍͠ͷʹ ऴྃ·Ͱʹ 808 ms ஗Ԇ͢Δ ! ࣮ࡍͷσʔλ͔Βൈਮͨ͠΋ͷɻ࣮ݧϓϩάϥϜʹ͸ Visual Basic 2015® Λ࢖༻ͨ͠ɻ ࣮ݧσʔλ -> σʔλ෼ੳʹෆศ
  6. ͜Ε·Ͱ (γϯάϧεϨου) 1000 ms + 1 ms 1000 ms +

    1 ms 1000 ms + 1 ms 3000 ms + 3 ms ஗Ԇ͕ੵΈॏͳΓऴྃ࣌ؒʹӨڹ
  7. ࣌ؒܭଌ

  8. ࣌ؒܭଌ •̋̋ͨ͠ͷ͸ XX ඵͩΑ •XX ඵޙʹ ̋̋ ͯ͠Ͷ Input Output

  9. ̋̋ͨ͠ͷ͸ XX ඵͩΑ Input

  10. ̋̋ͨ͠ͷ͸ XX ඵͩΑ -> ൓Ԡ࣌ؒܭଌ

  11. • time() • Date • gettimeofday() • clock_gettime() • clock_gettime_nsec_np()

    • mach_absolute_time() Swift ʹ͓͚Δ ൓Ԡ࣌ؒܭଌ iOS ͷ࣌ؒؔ਺ͷਫ਼౓ - Qiita @yamoridon Λݩʹ Xcode 10.1, Swift 4.2, iPhone X ؀ڥԼʹͯܭଌ 1.00 us 1.01 us 1.00 us 1.00 us 0.05 us 1,000,000.00 us = 1,000 ms 1 ms
  12. λονݕग़Ϩʔτ iOS Device Compatibility Reference - Apple Developer

  13. λονݕग़Ϩʔτ • iPhone X ͓Αͼ iPad Pro ͕ 120 Hz

    Ͱͷ ݕग़ ʹରԠ • iPad Pro (2018) ͕ 120 Hz Ͱͷ දࣔ ʹରԠ • ͦΕҎ֎͸ 60 Hz - 60 Hz iOS Device Compatibility Reference - Apple Developer -> ݕग़·Ͱ࠷େ 8.33 - 16.67 ms ͷ஗Ԇ
  14. XX ඵޙʹ ̋̋ ͯ͠Ͷ Output

  15. XX ඵޙʹ ̋̋ ͯ͠Ͷ -> λΠϚʔॲཧ

  16. Swift ʹ͓͚Δ λΠϚʔॲཧ OperantKit ΑΓɼXcode 10.1, Swift 4.2, iPhone X,

    MacBook Pro (15-inch, 2018) 2.9 GHz Intel Core i9 ؀ڥԼʹͯܭଌɻ While loop ͸ usleep(100) ΛೖΕͨ Async dispatch ʹ࣮ͯߦɻ Delay CPU OS While loop ±0 ms 25% All (include Linux) CADisplayLink +5 ms 9% iOS, tvOS (QuartzCore) CVDisplayLink +0~16 ms 3% macOS (QuartzCore)
  17. ͜Ε·Ͱ (γϯάϧεϨου) 1000 ms + 1 ms 1000 ms +

    1 ms 1000 ms + 1 ms 3000 ms + 3 ms ஗Ԇ͸͢Δ΋ͷͷɼ Ұఆͷ஗Ԇͱ1000 ms ͕ධՁ͞Ε͍ͯͨ
  18. ஗Ԇ͸มಈ͢Δ΋ͷͷɼ ʮఆظʯͱͯ͠͸ΑΓݱ࣮ੈքʹଈ͍ͯ͠Δ ඇಉظ (λΠϚʔΫϥε) Ͱ௨஌ notify 1000 ms notify notify

    1000 ms 1000 ms Log Log Log
  19. ஗Ԇ͕ώτʹٴ΅͢Өڹ

  20. 1. ώτ͸஗ԆΛ஌֮͢Δ͔?

  21. ஌֮͠ͳ͍

  22. ஌֮͠ͳ͍ • ʮίʔϥΛҿΊʯʮϙοϓίʔϯΛ৯΂Ζʯͱ͍͏จࣈྻΛ ແҙࣝԼ (୹࣌ؒʹ܁Γฦ͠) Ͱఄࣔ • Smarandescu & Shimp

    (2015) ͷݚڀͰ͸ɼ23 ms x 13 ճͷ ܹࢗఄ͕ࣔ௚ޙͷ঎඼બ୒ʹӨڹΛٴ΅͢͜ͱΛࣔͨ͠ɻ
  23. ஌֮͠ͳ͍ • ʮίʔϥΛҿΊʯʮϙοϓίʔϯΛ৯΂Ζʯͱ͍͏จࣈྻΛ ແҙࣝԼ (୹࣌ؒʹ܁Γฦ͠) Ͱఄࣔ -> αϒϦϛφϧޮՌ • Smarandescu

    & Shimp (2015) ͷݚڀͰ͸ɼ23 ms x 13 ճͷ ܹࢗఄ͕ࣔ௚ޙͷ঎඼બ୒ʹӨڹΛٴ΅͢͜ͱΛࣔͨ͠ɻ -> ͜ͷ࣌ɼ࣮ݧࢀՃऀͷશһ͕஌֮͠ͳ͔ͬͨ
  24. 2. ώτ͸஗Ԇͨ͠ϑΟʔυόοΫΛ ࣗ਎ͷߦಈͱೝࣝͰ͖Δ͔?

  25. ೝࣝͰ͖Δ

  26. • λονύωϧͷԁʹಛఆͷॱংͰλον͢Δͱ͓ۚͱަ׵ ՄೳͳϙΠϯτΛ֫ಘ • Okouchi (2009) ͷݚڀͰ͸ɼϙΠϯτ֫ಘʹ30ඵͷ ೝࣝͰ͖Δ ஗Ԇ͕͋ͬͯ΋൓ԠΛ֫ಘͨ͠

  27. • λονύωϧͷԁʹಛఆͷॱংͰλον͢Δͱ͓ۚͱަ׵ ՄೳͳϙΠϯτΛ֫ಘ • Okouchi (2009) ͷݚڀͰ͸ɼϙΠϯτ֫ಘʹ30ඵͷ ೝࣝͰ͖Δ -> ಉछܹࢗͷ஗Ԇ͸൓ԠܭଌʹӨڹ͠ͳ͍

    ஗Ԇ͕͋ͬͯ΋൓ԠΛ֫ಘͨ͠
  28. ·ͱΊ •λον౳ͷ൓Ԡݕग़͸஗ԆΛڐ༰ •ϑΟʔυόοΫ஗ԆΑΓλΠϚʔΛ༏ઌ -> ݕग़·Ͱ࠷େ 8.33 - 16.67 ms ͷ஗Ԇ

    -> ܭଌ஗Ԇ͸ 0.00005 ms -> දࣔ·Ͱ࠷େ 8.33 - 16.67 ms ͷ஗Ԇ
  29. Swift ʹ͓͚Δܦա࣌ؒͷܭଌ

  30. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ

  31. ࢀߟ • iOS ͷ࣌ؒؔ਺ͷਫ਼౓ - Qiita @yamoridon • iOS Device

    Compatibility Reference - Apple Developer • Okouchi, H. (2009). Response acquisition by humans with delayed reinforcement. Journal of the Experimental Analysis of Behavior, 91(3), 377-390. • OperantChamberApp - App Store • Smarandescu, L., & Shimp, T. A. (2015). Drink coca-cola, eat popcorn, and choose powerade: testing the limits of subliminal persuasion. Marketing Letters, 26(4), 715-726. • YutoMizutani/OperantKit - GitHub