{"id":486,"date":"2014-08-31T21:15:35","date_gmt":"2014-08-31T12:15:35","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=486"},"modified":"2014-12-03T10:07:21","modified_gmt":"2014-12-03T01:07:21","slug":"swift-array-dictionary-slow","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2014\/08\/swift-array-dictionary-slow\/","title":{"rendered":"Swift \u306e Array \/ Dictionary \u306f\u6700\u9069\u5316\u306a\u3057\u3067\u306f\u9045\u3044 (Xcode 6.1 \/ iOS 8.1 \u66f4\u65b0)"},"content":{"rendered":"

Swift \u306e Array\/Dictionary \u306f\u6700\u9069\u5316\u306a\u3057\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u5834\u5408, \u5b9f\u884c\u901f\u5ea6\u304c\u9045\u304f\u306a\u308a\u307e\u3059. NSMutableArray\/NSMutableDictionary \u3068\u6bd4\u3079\u3066\u3082\u304b\u306a\u308a\u9045\u3044\u7d50\u679c\u3068\u306a\u308a\u307e\u3059.<\/p>\n

<\/p>\n

\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9<\/h2>\n

\u3053\u306e\u554f\u984c\u3092\u30c6\u30b9\u30c8\u3059\u308b\u305f\u3081\u306b\u5358\u7d14\u306a\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f. NSMutableArray \u3068 Swift \u306e Array \u306b\u305d\u308c\u305e\u308c 1,000,000 \u500b\u306e\u8981\u7d20\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9\u3068, NSMutableDictionary \u3068 Swift \u306e Dictionary \u306b 100,000 \u500b\u306e\u8981\u7d20\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059.<\/p>\n

OS X \u306e Swift \u306f\u73fe\u6642\u70b9\u3067 Beta \u3068\u3055\u308c\u3066\u3044\u308b\u305f\u3081, iOS \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u4f5c\u6210\u3057\u307e\u3057\u305f. \u5229\u7528\u3057\u305f\u30b3\u30fc\u30c9\u306f GitHub<\/a> \u3067\u516c\u958b\u3057\u3066\u3044\u307e\u3059.<\/p>\n

\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u5b9f\u884c<\/h2>\n

Xcode \u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304d, \u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u5b9f\u884c\u3057\u307e\u3059. \u30a2\u30d7\u30ea\u5185\u306e Run Benchmark \u3092\u30bf\u30c3\u30d7\u3059\u308b\u3068\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3057, UIAlertView \u3067\u7d50\u679c\u3092\u8868\u793a\u3057\u307e\u3059.<\/p>\n

Swift \u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u306b\u306f Xcode 6.0.1 (6A317) \u306e\u6642\u70b9\u3067, -Onone (\u6700\u9069\u5316\u306a\u3057), -O (\u6700\u9069\u5316\u3042\u308a), -Ounchecked (\u6700\u9069\u5316\u3042\u308a, \u5b9f\u884c\u6642\u306e\u69d8\u3005\u306a\u30c1\u30a7\u30c3\u30af\u3092\u884c\u308f\u306a\u3044) \u304c\u3042\u308a\u307e\u3059. \u3053\u308c\u3089\u306e3\u7a2e\u985e\u306e\u6700\u9069\u5316\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u5207\u308a\u66ff\u3048\u3066\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6e2c\u5b9a\u3057\u307e\u3059.<\/p>\n

-Ofast \u306f Xcode 6 Beta 5 \u304b\u3089 -Ounchecked \u306b\u5909\u66f4\u3055\u308c\u307e\u3057\u305f.<\/p>\n

\u30c6\u30b9\u30c8\u7d50\u679c<\/h2>\n

\u30c6\u30b9\u30c8\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f. \u5171\u901a\u306e\u74b0\u5883\u306f\u6b21\u306e\u901a\u308a\u3067\u3059: OS X Yosemite (14A329f) \/ Xcode 6.0.1 (6A317)<\/p>\n

iPhone 5s Simulator \/ iOS 8 (12A365)<\/h3>\n

\"Comparison<\/a><\/p>\n

Onone<\/h4>\n
 \r\nNSMutableArray:      0.32 [sec]\r\nSwift Array:         7.02 [sec]\r\nNSMutableDictionary: 0.08 [sec]\r\nSwift Dictionary:    2.04 [sec]\r\n<\/pre>\n

O<\/h4>\n
 \r\nNSMutableArray:      0.11 [sec]\r\nSwift Array:         0.06 [sec]\r\nNSMutableDictionary: 0.05 [sec]\r\nSwift Dictionary:    0.02 [sec]\r\n<\/pre>\n

Ounchecked<\/h4>\n
 \r\nNSMutableArray:      0.11 [sec]\r\nSwift Array:         0.10 [sec]\r\nNSMutableDictionary: 0.05 [sec]\r\nSwift Dictionary:    0.02 [sec]\r\n<\/pre>\n

iPhone 5s \/ iOS 8 (12A365)<\/h3>\n

\"Comparison<\/a><\/p>\n

Onone<\/h4>\n
 \r\nNSMutableArray:      0.80 [sec]\r\nSwift Array:        29.15 [sec]\r\nNSMutableDictionary: 0.19 [sec]\r\nSwift Dictionary:    8.27 [sec]\r\n<\/pre>\n

O<\/h4>\n
 \r\nNSMutableArray:      0.14 [sec]\r\nSwift Array:         0.28 [sec]\r\nNSMutableDictionary: 0.09 [sec]\r\nSwift Dictionary:    0.10 [sec]\r\n<\/pre>\n

Ounchecked<\/h4>\n
 \r\nNSMutableArray:      0.14 [sec]\r\nSwift Array:         0.51 [sec]\r\nNSMutableDictionary: 0.10 [sec]\r\nSwift Dictionary:    0.10 [sec]\r\n<\/pre>\n

Simulator (x64) \u3068 iPhone 5s (arm64) \u3067\u5c11\u3057\u50be\u5411\u304c\u7570\u306a\u308a\u307e\u3059.<\/p>\n

\u3069\u3061\u3089\u306b\u3082\u5171\u901a\u3057\u3066\u8a00\u3048\u308b\u3053\u3068\u306f, \u6700\u9069\u5316\u306a\u3057\u306e\u5834\u5408, Swift \u306e Array \u3068 Dictionary \u306f\u5727\u5012\u7684\u306b\u9045\u304f NSMutableArray \u3068 NSMutableDictionary \u306b\u6bd4\u3079\u3066\u6570\u5341\u500d\u306e\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u307e\u3059.<\/p>\n

\u6700\u9069\u5316\u3092\u884c\u3063\u305f\u5834\u5408\u306f\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306b\u3088\u308a\u50be\u5411\u304c\u7570\u306a\u308a, Intel \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u5834\u5408\u306f Swift \u306e Array \u3068 Dictionary \u306e\u65b9\u304c\u9ad8\u901f\u306b\u5b9f\u884c\u3067\u304d, NSMutableArray \u3068 NSMutableDictionary \u306b\u6bd4\u3079\u3066\u7d04\u534a\u5206\u306e\u6642\u9593\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059. \u3057\u304b\u3057, ARM \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u5834\u5408\u306f Swift \u306e Array \u3068 Dictionary \u306e\u65b9\u304c\u9045\u304f NSMutableArray \u3068 NSMutableDictionary \u306b\u6bd4\u3079\u3066\u7d041\u301c2\u500d\u306e\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059.<\/p>\n

\u307e\u3068\u3081<\/h2>\n

Swift \u306e Array \u3068 Dictionary \u306f\u6700\u9069\u5316\u7121\u3057\u3067\u5b9f\u884c\u3059\u308b\u3068\u975e\u5e38\u306b\u9045\u304f\u306a\u308a\u307e\u3059. \u3057\u304b\u3057, \u6700\u9069\u5316\u3092\u884c\u3046\u3068 Intel \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u306f NSMutableArray \u3084 NSMutableDictionary \u7d04\u534a\u5206\u306e\u6642\u9593\u3067, ARM \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u306f\u6570\u500d\u306e\u6642\u9593\u3067\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059.<\/p>\n

\u5b9f\u969b\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3059\u308b\u5834\u5408, \u30c7\u30d0\u30c3\u30b0\u30d3\u30eb\u30c9\u306f\u6700\u9069\u5316\u306a\u3057\u3067\u884c\u3046\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u304c, Swift \u3067\u3053\u308c\u3092\u884c\u3046\u3068\u4e88\u60f3\u4ee5\u4e0a\u306b\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u4f4e\u4e0b\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059. \u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u9593\u306f\u9577\u304f\u306a\u308a\u307e\u3059\u304c, \u30ea\u30ea\u30fc\u30b9\u3059\u308b\u3082\u306e\u3068\u8fd1\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3067\u5b9f\u884c\u3057\u305f\u3044\u5834\u5408\u306f, \u30c7\u30d0\u30c3\u30b0\u30d3\u30eb\u30c9\u3067\u3082\u6700\u9069\u5316\u3092\u884c\u3046\u307b\u3046\u304c\u826f\u3055\u305d\u3046\u3067\u3059.<\/p>\n

\u4eca\u5f8c\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3067\u6539\u5584\u3055\u308c\u3066\u3044\u304f\u3068\u306f\u601d\u3044\u307e\u3059\u304c, Apple \u306b\u306f Swift \u306e\u6700\u9069\u5316\u306a\u3057\u3067\u306e\u5b9f\u884c\u901f\u5ea6\u306e\u6539\u5584\u3068 ARM \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3067\u306e\u6700\u9069\u5316\u306e\u6539\u5584\u3092\u671b\u307f\u305f\u3044\u3068\u3053\u308d\u3067\u3059.<\/p>\n

\u8ffd\u8a18: Xcode 6.1 \/ iOS 8.1 \u3067\u306e\u30c6\u30b9\u30c8\u7d50\u679c<\/h2>\n

Xcode 6.1 \u3068 iOS 8.1 \u304c\u6b63\u5f0f\u30ea\u30ea\u30fc\u30b9\u3068\u306a\u3063\u305f\u305f\u3081, \u6539\u3081\u3066 iPhone 5s \u5b9f\u6a5f\u3068 iPhone 5s Simulator \u3067\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3057\u305f. \u5171\u901a\u306e\u74b0\u5883\u306f\u6b21\u306e\u901a\u308a\u3067\u3059: OS X Yosemite (14A388a) \/ Xcode 6.1 (6A1052d) \/ iOS 8.1 (12B411) <\/p>\n

iPhone 5s Simulator \/ iOS 8.1 (12B411)<\/h3>\n

\"Comparison<\/a><\/p>\n

Onone<\/h4>\n
 \r\nNSMutableArray:      0.34  [sec]\r\nSwift Array:         6.61  [sec]\r\nNSMutableDictionary: 0.073 [sec]\r\nSwift Dictionary:    2.58  [sec]\r\n<\/pre>\n

O<\/h4>\n
 \r\nNSMutableArray:      0.12  [sec]\r\nSwift Array:         0.014 [sec]\r\nNSMutableDictionary: 0.048 [sec]\r\nSwift Dictionary:    0.036 [sec]\r\n<\/pre>\n

Ounchecked<\/h4>\n
 \r\nNSMutableArray:      0.12 [sec]\r\nSwift Array:         0.014 [sec]\r\nNSMutableDictionary: 0.047 [sec]\r\nSwift Dictionary:    0.033 [sec]\r\n<\/pre>\n

iPhone 5s \/ iOS 8.1 (12B411)<\/h3>\n

\"Comparison<\/a><\/p>\n

Onone<\/h4>\n
 \r\nNSMutableArray:      0.88 [sec]\r\nSwift Array:        27.9  [sec]\r\nNSMutableDictionary: 0.21 [sec]\r\nSwift Dictionary:   10.9  [sec]\r\n<\/pre>\n

O<\/h4>\n
 \r\nNSMutableArray:      0.14  [sec]\r\nSwift Array:         0.029 [sec]\r\nNSMutableDictionary: 0.085 [sec]\r\nSwift Dictionary:    0.16  [sec]\r\n<\/pre>\n

Ounchecked<\/h4>\n
 \r\nNSMutableArray:      0.14  [sec]\r\nSwift Array:         0.031 [sec]\r\nNSMutableDictionary: 0.088 [sec]\r\nSwift Dictionary:    0.15  [sec]\r\n<\/pre>\n

\u8ffd\u8a18: Xcode 6.1 \/ iOS 8.1 \u307e\u3068\u3081<\/h2>\n

Xcode 6.1 \u3068 iOS 8.1 \u3067\u306f Swift \u306e Array \u304c\u5927\u304d\u304f\u9ad8\u901f\u5316<\/strong>\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059. \u6700\u9069\u5316\u3042\u308a\u306e\u5834\u5408 Intel \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3, ARM \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3068\u3082\u306b, NSMutableArray \u3088\u308a\u3082\u6570\u500d\u301c10\u500d\u7a0b\u5ea6\u9ad8\u901f\u306b\u306a\u3063\u3066\u3044\u307e\u3059.<\/p>\n

\u4e00\u65b9\u3067 Swift \u306e Dictionary \u306e\u901f\u5ea6\u306b\u306f\u3042\u307e\u308a\u6539\u5584\u304c\u898b\u3089\u308c\u306a\u3044\u3088\u3046\u3067\u3059. \u4eca\u5f8c\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3067\u306e\u6539\u5584\u306b\u671f\u5f85\u3067\u3059.<\/p>\n","protected":false},"excerpt":{"rendered":"

Swift \u306e Array\/Dictionary \u306f\u6700\u9069\u5316\u306a\u3057\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u5834\u5408, \u5b9f\u884c\u901f\u5ea6\u304c\u9045\u304f\u306a\u308a\u307e\u3059. NSMutableArray\/NSMutableDictionary \u3068\u6bd4\u3079\u3066\u3082\u304b\u306a\u308a\u9045\u3044\u7d50\u679c\u3068\u306a\u308a\u307e\u3059.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[11,60],"_links":{"self":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/486"}],"collection":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":31,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/posts\/486\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ymyzk.com\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}