Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ARC vs MRC performance test projects

  • Loading branch information...
commit f328d87b77c4e2a2eb70f5090aa4b7c25732c85d 1 parent 40384f4
@LearnCocos2D LearnCocos2D authored
Showing with 36,534 additions and 0 deletions.
  1. +1,586 −0 Cocos2D-ARC-Performance-Test/Cocos2D-ARC-Performance-Test.xcodeproj/project.pbxproj
  2. +23 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/ARCTests.h
  3. +88 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/ARCTests.m
  4. +28 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/AppDelegate.h
  5. +175 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/AppDelegate.m
  6. +23 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/HelloWorldLayer.h
  7. +116 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/HelloWorldLayer.m
  8. +28 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosome.h
  9. +181 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosome.m
  10. +29 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosomeARC.h
  11. +185 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosomeARC.m
  12. +23 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgo.h
  13. +153 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgo.m
  14. +23 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgoARC.h
  15. +152 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgoARC.m
  16. +23 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/MRCTests.h
  17. +90 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/MRCTests.m
  18. +98 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester.h
  19. +588 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester.mm
  20. +135 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_ARCvsMRC.m
  21. +147 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_Arithmetic.mm
  22. +490 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_Array.mm
  23. +70 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_IO.mm
  24. +54 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_Memory.mm
  25. +275 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_Messaging.mm
  26. +167 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_Misc.mm
  27. +202 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_NodeHierarchy.mm
  28. +173 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_ObjectCompare.mm
  29. +188 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_ObjectCreation.mm
  30. +326 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_TextureLoading.mm
  31. +14 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Prefix.pch
  32. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Arial14.GlyphProject
  33. +179 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Arial14.fnt
  34. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Arial14.png
  35. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Default-568h@2x.png
  36. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Default.png
  37. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Icon-72.png
  38. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Icon-Small-50.png
  39. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Icon-Small.png
  40. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Icon-Small@2x.png
  41. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Icon.png
  42. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Icon@2x.png
  43. +54 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/Info.plist
  44. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/dg_grounds32.png
  45. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/fps_images.png
  46. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/iTunesArtwork
  47. +412 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas.plist
  48. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas.png
  49. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas.tps
  50. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC2.pvr
  51. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC2.pvr.ccz
  52. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC2.pvr.gz
  53. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC2_no-alpha.pvr
  54. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC2_no-alpha.pvr.ccz
  55. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC2_no-alpha.pvr.gz
  56. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC4.pvr
  57. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC4.pvr.ccz
  58. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC4.pvr.gz
  59. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC4_no-alpha.pvr
  60. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC4_no-alpha.pvr.ccz
  61. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_PVRTC4_no-alpha.pvr.gz
  62. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGB565.jpg
  63. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGB565.png
  64. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGB565.pvr
  65. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGB565.pvr.ccz
  66. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGB565.pvr.gz
  67. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA4444.jpg
  68. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA4444.png
  69. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA4444.pvr
  70. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA4444.pvr.ccz
  71. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA4444.pvr.gz
  72. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA5551.jpg
  73. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA5551.png
  74. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA5551.pvr
  75. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA5551.pvr.ccz
  76. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA5551.pvr.gz
  77. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA8888.jpg
  78. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA8888.png
  79. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA8888.pvr
  80. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA8888.pvr.ccz
  81. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/textureatlas_RGBA8888.pvr.gz
  82. +11 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/tilemap-gigantic.tmx
  83. +11 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/tilemap-large.tmx
  84. +11 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/Resources/tilemap-small.tmx
  85. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/dp1.caf
  86. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/dp2.caf
  87. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/dp3.caf
  88. BIN  Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/dp4.caf
  89. +243 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDAudioManager.h
  90. +888 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDAudioManager.m
  91. +60 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDConfig.h
  92. +77 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDOpenALSupport.h
  93. +250 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDOpenALSupport.m
  94. +232 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDXMacOSXSupport.h
  95. +175 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDXMacOSXSupport.m
  96. +45 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDXPropertyModifierAction.h
  97. +123 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CDXPropertyModifierAction.m
  98. +440 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CocosDenshion.h
  99. +1,610 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/CocosDenshion.m
  100. +5 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/README.md
  101. +90 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/SimpleAudioEngine.h
  102. +220 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/CocosDenshion/SimpleAudioEngine.m
  103. +23 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/LICENSE_CocosDenshion.txt
  104. +35 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/LICENSE_Kazmath.txt
  105. +85 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/LICENSE_artwork.txt
  106. +24 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/LICENSE_cocos2d.txt
  107. +195 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAction.h
  108. +357 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAction.m
  109. +75 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionCamera.h
  110. +147 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionCamera.m
  111. +151 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionCatmullRom.h
  112. +384 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionCatmullRom.m
  113. +245 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionEase.h
  114. +534 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionEase.m
  115. +165 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionGrid.h
  116. +386 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionGrid.m
  117. +208 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionGrid3D.h
  118. +642 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionGrid3D.m
  119. +235 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionInstant.h
  120. +509 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionInstant.m
  121. +473 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionInterval.h
  122. +1,585 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionInterval.m
  123. +113 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionManager.h
  124. +338 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionManager.m
  125. +43 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionPageTurn3D.h
  126. +87 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionPageTurn3D.m
  127. +59 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionProgressTimer.h
  128. +103 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionProgressTimer.m
  129. +219 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionTiledGrid.h
  130. +770 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionTiledGrid.m
  131. +62 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionTween.h
  132. +72 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCActionTween.m
  133. +150 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAnimation.h
  134. +200 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAnimation.m
  135. +74 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAnimationCache.h
  136. +250 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAnimationCache.m
  137. +98 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAtlasNode.h
  138. +212 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCAtlasNode.m
  139. +98 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCCamera.h
  140. +148 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCCamera.m
  141. +77 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCClippingNode.h
  142. +329 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCClippingNode.m
  143. +144 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCConfiguration.h
  144. +315 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCConfiguration.m
  145. +347 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCDirector.h
  146. +671 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCDirector.m
  147. +65 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCDrawNode.h
  148. +377 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCDrawNode.m
  149. +162 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCDrawingPrimitives.h
  150. +407 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCDrawingPrimitives.m
  151. +173 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCGLProgram.h
  152. +466 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCGLProgram.m
  153. +44 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCGrabber.h
  154. +99 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCGrabber.m
  155. +130 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCGrid.h
  156. +584 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCGrid.m
  157. +71 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLabelAtlas.h
  158. +214 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLabelAtlas.m
  159. +240 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLabelBMFont.h
  160. +1,023 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLabelBMFont.m
  161. +132 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLabelTTF.h
  162. +316 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLabelTTF.m
  163. +303 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLayer.h
  164. +874 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCLayer.m
  165. +96 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCMenu.h
  166. +545 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCMenu.m
  167. +428 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCMenuItem.h
  168. +843 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCMenuItem.m
  169. +86 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCMotionStreak.h
  170. +280 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCMotionStreak.m
  171. +39 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCNode+Debug.h
  172. +71 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCNode+Debug.m
  173. +619 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCNode.h
  174. +1,032 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCNode.m
  175. +50 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParallaxNode.h
  176. +161 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParallaxNode.m
  177. +99 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleBatchNode.h
  178. +473 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleBatchNode.m
  179. +117 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleExamples.h
  180. +926 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleExamples.m
  181. +464 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleSystem.h
  182. +929 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleSystem.m
  183. +73 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleSystemQuad.h
  184. +493 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCParticleSystemQuad.m
  185. +58 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCPhysicsDebugNode.h
  186. +185 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCPhysicsDebugNode.m
  187. +82 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCPhysicsSprite.h
  188. +187 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCPhysicsSprite.mm
  189. +92 −0 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/libs/cocos2d/CCProgressTimer.h
Sorry, we could not display the entire diff because too many files (716) changed.
View
1,586 Cocos2D-ARC-Performance-Test/Cocos2D-ARC-Performance-Test.xcodeproj/project.pbxproj
1,586 additions, 0 deletions not shown
View
23 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/ARCTests.h
@@ -0,0 +1,23 @@
+//
+// ARCTests.h
+// Cocos2D-ARC-Performance-Test
+//
+// Created by Steffen Itterheim on 20.03.13.
+//
+//
+
+#import <Foundation/Foundation.h>
+
+@interface ARCTests : NSObject
+
+@property (nonatomic, copy) NSString* string;
+
++(id) arcTests;
+-(void) createAutoreleaseObject;
+-(void) createAllocInitObject;
+-(void) messageThatDoesNothing;
+-(CCNode*) createAndReturnAutoreleaseObject;
+-(BOOL) data:(NSData*)data containsCString:(char *)cmp;
+-(void) runGeneticAlgorithm;
+
+@end
View
88 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/ARCTests.m
@@ -0,0 +1,88 @@
+//
+// ARCTests.m
+// Cocos2D-ARC-Performance-Test
+//
+// Created by Steffen Itterheim on 20.03.13.
+//
+//
+
+#import "cocos2d.h"
+#import "ARCTests.h"
+
+#import "JASGeneticAlgoARC.h"
+
+@implementation ARCTests
+
++(id) arcTests
+{
+ return [[self alloc] init];
+}
+
+-(void) dealloc
+{
+ //NSLog(@"ARC Test dealloc");
+}
+
+-(void) createAutoreleaseObject
+{
+ @autoreleasepool
+ {
+ CCNode* test = [CCNode node];
+ test = nil;
+ }
+}
+
+-(void) createAllocInitObject
+{
+ CCNode* test = [[CCNode alloc] init];
+ test = nil;
+}
+
+-(CCNode*) createAndReturnAutoreleaseObject
+{
+ return [CCNode node];
+}
+
+-(void) messageThatDoesNothing
+{
+}
+
+// code from Jeff LaMarche:
+// http://iphonedevelopment.blogspot.de/2008/04/root-of-all-evil-introduction-to.html
+-(BOOL) data:(NSData*)data containsCString:(char *)cmp
+{
+ @autoreleasepool
+ {
+ BOOL retval = NO;
+ NSUInteger offset = 0;
+ char * byte;
+ const char * bytes = [data bytes];
+
+ while (offset < [data length])
+ {
+ byte = (char *)bytes;
+
+ NSString * checkString = [NSString stringWithCString:byte encoding:NSUTF8StringEncoding];
+ if ([checkString isEqualToString:[NSString stringWithCString:cmp encoding:NSUTF8StringEncoding]])
+ {
+ retval = YES;
+ break;
+ }
+
+ offset++;
+ }
+ return retval;
+ }
+}
+
+-(void) runGeneticAlgorithm
+{
+ @autoreleasepool
+ {
+ NSString* sequence = @"lks89Ü?c§cngW3d432d7cf143497fb5a95b280f873b16iysöl5cöä#ke2ß0B% ()=BÄ´Qyaix4@\nElapsou5ö8o7 5V4*j6ß71655b7c7b6cb41128dffc046773acfbc8w3y,ic;9uwo9ly8WV)+:.573j 4jpew Q'C)96ß#8m)$VNwv49";
+ JASGeneticAlgoARC *algo = [[JASGeneticAlgoARC alloc] initWithTargetSequence:sequence];
+ [algo execute];
+ }
+}
+
+@end
View
28 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/AppDelegate.h
@@ -0,0 +1,28 @@
+//
+// AppDelegate.h
+// c21-templatetest
+//
+// Created by Steffen Itterheim on 19.03.13.
+// Copyright Steffen Itterheim 2013. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "cocos2d.h"
+
+// Added only for iOS 6 support
+@interface MyNavigationController : UINavigationController <CCDirectorDelegate>
+@end
+
+@interface AppController : NSObject <UIApplicationDelegate>
+{
+ UIWindow *window_;
+ MyNavigationController *navController_;
+
+ CCDirectorIOS *__weak director_; // weak ref
+}
+
+@property (nonatomic, strong) UIWindow *window;
+@property (readonly) MyNavigationController *navController;
+@property (weak, readonly) CCDirectorIOS *director;
+
+@end
View
175 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/AppDelegate.m
@@ -0,0 +1,175 @@
+//
+// AppDelegate.m
+// c21-templatetest
+//
+// Created by Steffen Itterheim on 19.03.13.
+// Copyright Steffen Itterheim 2013. All rights reserved.
+//
+
+#import "cocos2d.h"
+
+#import "AppDelegate.h"
+#import "HelloWorldLayer.h"
+
+@implementation MyNavigationController
+
+// The available orientations should be defined in the Info.plist file.
+// And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method.
+// Only valid for iOS 6+. NOT VALID for iOS 4 / 5.
+-(NSUInteger)supportedInterfaceOrientations {
+
+ // iPhone only
+ if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
+ return UIInterfaceOrientationMaskLandscape;
+
+ // iPad only
+ return UIInterfaceOrientationMaskLandscape;
+}
+
+// Supported orientations. Customize it for your own needs
+// Only valid on iOS 4 / 5. NOT VALID for iOS 6.
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ // iPhone only
+ if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
+ return UIInterfaceOrientationIsLandscape(interfaceOrientation);
+
+ // iPad only
+ // iPhone only
+ return UIInterfaceOrientationIsLandscape(interfaceOrientation);
+}
+
+// This is needed for iOS4 and iOS5 in order to ensure
+// that the 1st scene has the correct dimensions
+// This is not needed on iOS6 and could be added to the application:didFinish...
+-(void) directorDidReshapeProjection:(CCDirector*)director
+{
+ if(director.runningScene == nil) {
+ // Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
+ // and add the scene to the stack. The director will run it when it automatically when the view is displayed.
+ [director runWithScene: [HelloWorldLayer scene]];
+ }
+}
+@end
+
+
+@implementation AppController
+
+@synthesize window=window_, navController=navController_, director=director_;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ // Create the main window
+ window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+
+
+ // Create an CCGLView with a RGB565 color buffer, and a depth buffer of 0-bits
+ CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
+ pixelFormat:kEAGLColorFormatRGB565 //kEAGLColorFormatRGBA8
+ depthFormat:0 //GL_DEPTH_COMPONENT24_OES
+ preserveBackbuffer:NO
+ sharegroup:nil
+ multiSampling:NO
+ numberOfSamples:0];
+
+ director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
+
+ director_.wantsFullScreenLayout = YES;
+
+ // Display FSP and SPF
+ [director_ setDisplayStats:YES];
+
+ // set FPS at 60
+ [director_ setAnimationInterval:1.0/60];
+
+ // attach the openglView to the director
+ [director_ setView:glView];
+
+ // 2D projection
+ [director_ setProjection:kCCDirectorProjection2D];
+ // [director setProjection:kCCDirectorProjection3D];
+
+ // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
+ if( ! [director_ enableRetinaDisplay:YES] )
+ CCLOG(@"Retina Display Not supported");
+
+ // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
+ // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
+ // You can change this setting at any time.
+ [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
+
+ // If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
+ // On iPad HD : "-ipadhd", "-ipad", "-hd"
+ // On iPad : "-ipad", "-hd"
+ // On iPhone HD: "-hd"
+ CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
+ [sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
+ [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
+ [sharedFileUtils setiPadSuffix:@"-ipad"]; // Default on iPad is "ipad"
+ [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd"
+
+ // Assume that PVR images have premultiplied alpha
+ [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
+
+ // Create a Navigation Controller with the Director
+ navController_ = [[MyNavigationController alloc] initWithRootViewController:director_];
+ navController_.navigationBarHidden = YES;
+
+ // for rotation and other messages
+ [director_ setDelegate:navController_];
+
+ // set the Navigation Controller as the root view controller
+ [window_ setRootViewController:navController_];
+
+ // make main window visible
+ [window_ makeKeyAndVisible];
+
+ return YES;
+}
+
+// getting a call, pause the game
+-(void) applicationWillResignActive:(UIApplication *)application
+{
+ if( [navController_ visibleViewController] == director_ )
+ [director_ pause];
+}
+
+// call got rejected
+-(void) applicationDidBecomeActive:(UIApplication *)application
+{
+ [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
+ if( [navController_ visibleViewController] == director_ )
+ [director_ resume];
+}
+
+-(void) applicationDidEnterBackground:(UIApplication*)application
+{
+ if( [navController_ visibleViewController] == director_ )
+ [director_ stopAnimation];
+}
+
+-(void) applicationWillEnterForeground:(UIApplication*)application
+{
+ if( [navController_ visibleViewController] == director_ )
+ [director_ startAnimation];
+}
+
+// application will be killed
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ CC_DIRECTOR_END();
+}
+
+// purge memory
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
+{
+ [[CCDirector sharedDirector] purgeCachedData];
+}
+
+// next delta time will be zero
+-(void) applicationSignificantTimeChange:(UIApplication *)application
+{
+ [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
+}
+
+@end
View
23 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/HelloWorldLayer.h
@@ -0,0 +1,23 @@
+//
+// HelloWorldLayer.h
+// Cocos2D-Performance-Test
+//
+// Copyright Steffen Itterheim 2011. Distributed under MIT License.
+//
+
+#import "cocos2d.h"
+#import "PerfTester.h"
+
+@interface HelloWorldLayer : CCLayer
+{
+ PerfTester* pt;
+ CCNode* __weak testNode;
+}
+
+@property (weak, nonatomic, readonly) CCNode* testNode;
+
++(CCScene *) scene;
+
++(HelloWorldLayer*) sharedLayer;
+
+@end
View
116 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/HelloWorldLayer.m
@@ -0,0 +1,116 @@
+//
+// HelloWorldLayer.m
+// Cocos2D-Performance-Test
+//
+// Copyright Steffen Itterheim 2011. Distributed under MIT License.
+//
+
+#import "HelloWorldLayer.h"
+#import "SimpleAudioEngine.h"
+
+static HelloWorldLayer* instance;
+
+@interface HelloWorldLayer (PrivateMethods)
+-(void) test:(ccTime)delta;
+@end
+
+@implementation HelloWorldLayer
+
+@synthesize testNode;
+
++(HelloWorldLayer*) sharedLayer
+{
+ return instance;
+}
+
++(CCScene *) scene
+{
+ CCScene *scene = [CCScene node];
+ HelloWorldLayer *layer = [HelloWorldLayer node];
+ [scene addChild: layer];
+ return scene;
+}
+
+-(id) init
+{
+ if ((self = [super init]))
+ {
+ instance = self;
+
+ testNode = [CCNode node];
+ [self addChild:testNode];
+
+ SimpleAudioEngine* simpleAudio = [SimpleAudioEngine sharedEngine];
+ [simpleAudio preloadEffect:@"dp2.caf"];
+
+ CGSize winSize = [CCDirector sharedDirector].winSize;
+
+ CCLabelTTF* label = [CCLabelTTF labelWithString:@"Testing ... be patient!" fontName:@"Arial" fontSize:30];
+ label.position = CGPointMake(winSize.width / 2, winSize.height / 2);
+ label.color = ccYELLOW;
+ [self addChild:label];
+
+ CCLabelTTF* label2 = [CCLabelTTF labelWithString:@"Enable Xcode Debug Console to see progress:" fontName:@"Arial" fontSize:16];
+ label2.position = CGPointMake(winSize.width / 2, winSize.height / 2 - 35);
+ label2.color = ccGREEN;
+ [self addChild:label2];
+
+ CCLabelTTF* label3 = [CCLabelTTF labelWithString:@"View -> Debug Area -> Activate Console" fontName:@"Arial" fontSize:16];
+ label3.position = CGPointMake(winSize.width / 2, winSize.height / 2 - 60);
+ label3.color = ccGREEN;
+ [self addChild:label3];
+
+ [self schedule:@selector(test:) interval:0.2f];
+ }
+ return self;
+}
+
+// Test done in onEnter to make sure Cocos2D is fully initialized
+-(void) test:(ccTime)delta
+{
+ [self unschedule:_cmd];
+
+ pt = [[PerfTester alloc] init];
+ pt.quickTest = NO;
+
+ [pt test:kkPerformanceTestARCvsMRC_Messaging];
+ [pt test:kkPerformanceTestARCvsMRC_AllocInit];
+ [pt test:kkPerformanceTestARCvsMRC_Autorelease];
+ [pt test:kkPerformanceTestARCvsMRC_Algorithm];
+
+ [pt test:KKPerformanceTestObjectCreation];
+ [pt test:KKPerformanceTestMessaging];
+ [pt test:kkPerformanceTestObjectCompare];
+ [pt test:kkPerformanceTestArray];
+ //[pt test:KKPerformanceTestTextureLoading];
+ [pt test:kkPerformanceTestNodeHierarchy];
+ [pt test:kkPerformanceTestArithmetic];
+ [pt test:kkPerformanceTestMemory];
+ [pt test:KKPerformanceTestIO];
+ [pt test:kkPerformanceTestMisc];
+
+ [pt printResultsToStandardOutput];
+ [pt showResultsInView:[CCDirector sharedDirector].view];
+
+ NSLog(@"Tests finishiablyed!");
+ [[SimpleAudioEngine sharedEngine] playEffect:@"dp2.caf"];
+
+ self.touchEnabled = YES;
+}
+
+-(void) dealloc
+{
+ instance = nil;
+}
+
+-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [[pt webView] goBack];
+
+}
+-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [[pt webView] goBack];
+}
+
+@end
View
28 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosome.h
@@ -0,0 +1,28 @@
+//
+// JASChromosome.h
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface JASChromosome : NSObject
+
+// Returns a copy of this chromosome's genes.
+@property (nonatomic, readonly, strong) NSString *geneSequence;
+
+// Designated initializer.
+- (id)initWithGeneCount:(NSUInteger)count;
+
+// Creates a new chromosome based on the gene
+// sequences of this chromosome and another one.
+- (JASChromosome *)mateWithChromosome:(JASChromosome *)other;
+
+// Returns YES if this chromosome's fitness is better
+// than the other chromosome's fitness.
+- (BOOL)isFitterThanChromosome:(JASChromosome *)other
+ forTargetSequence:(NSString *)sequence;
+
+@end
View
181 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosome.m
@@ -0,0 +1,181 @@
+//
+// JASChromosome.m
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import "JASChromosome.h"
+
+#define ARC4RANDOM_MAX (0x100000000) // The highest value returned by arc4random()
+#define FIRST_CHAR (32) // ' '
+#define LAST_CHAR (122) // 'Z'
+#define MUTATION_DELTA_MAX (6) // Mutate one gene by no more than +/-5.
+#define MUTATION_RATE (0.20f) // Mutate about 20% of the time
+#define MUTATION_THRESHOLD (ARC4RANDOM_MAX * MUTATION_RATE) // This is used to determine if a mutation should occur.
+#define RANDOM() (arc4random()) // Creates a random positive whole number
+#define RANDOM_MOD(__MOD) (arc4random_uniform(__MOD)) // Creates a random positive whole number no greater than __MOD-1
+
+@interface JASChromosome ()
+@property (nonatomic, strong) NSNumber *cachedOverallFitness;
+@property (nonatomic, strong) NSMutableArray *fitnessBuffer;
+@property (nonatomic, strong) NSMutableString *geneBuffer;
+
+// Calculates the overall fitness of this chromosome's gene sequence,
+// with respect to the target gene sequence.
+- (NSInteger)fitnessForTargetSequence:(NSString *)seq;
+
+// Calculates the fitness of one gene in the chromosome.
+- (NSInteger)fitnessOfGeneAtIndex:(NSUInteger)geneIndex
+ forTargetSequence:(NSString *)seq;
+
+// Performs a random mutation on one gene in the chromosome.
+- (void)mutate;
+@end
+
+
+@implementation JASChromosome
+
+@synthesize cachedOverallFitness;
+@synthesize fitnessBuffer;
+@synthesize geneBuffer;
+
+@dynamic geneSequence;
+- (NSString *)geneSequence
+{
+ return [NSString stringWithString:geneBuffer];
+}
+
+- (id)initWithGeneCount:(NSUInteger)count
+{
+ self = [super init];
+ if (self)
+ {
+ self.fitnessBuffer = [NSMutableArray arrayWithCapacity:count];
+ self.geneBuffer = [NSMutableString stringWithCapacity:count];
+ for (int geneIndex = 0; geneIndex < count; ++geneIndex)
+ {
+ // Append a random character between ' ' and 'Z'.
+ int value = RANDOM_MOD(LAST_CHAR - FIRST_CHAR);
+ value += FIRST_CHAR;
+ NSString *gene = [NSString stringWithFormat:@"%c", value];
+ [self.geneBuffer appendString:gene];
+ }
+ }
+ return self;
+}
+
+- (JASChromosome *)mateWithChromosome:(JASChromosome *)other
+{
+ // Create an empty chromosome.
+ JASChromosome *child = [[JASChromosome alloc] initWithGeneCount:0];
+
+ // Declare loop variables.
+ NSUInteger count = self.geneBuffer.length;
+ NSNumber *mine, *theirs;
+ JASChromosome *winner;
+ unichar geneValue;
+ NSString *gene;
+
+ // Fill the new chromosome's gene buffer with
+ // the fittest genes from both parents.
+ for (int i = 0; i < count; ++i)
+ {
+ // Get the same gene from both chromosomes.
+ mine = [self.fitnessBuffer objectAtIndex:i];
+ theirs = [other.fitnessBuffer objectAtIndex:i];
+
+ // Determine which chromosome's gene is fitter.
+ winner = [mine integerValue] > [theirs integerValue]
+ ? self
+ : other;
+
+ // Add the winner's gene to the child chromosome.
+ geneValue = [winner.geneBuffer characterAtIndex:i];
+ gene = [NSString stringWithFormat:@"%c", geneValue];
+ [child.geneBuffer appendString:gene];
+ }
+
+ // Sometimes randomly modify the child's gene sequence.
+ if (RANDOM() < MUTATION_THRESHOLD)
+ {
+ [child mutate];
+ }
+
+ return [child autorelease];
+}
+
+- (BOOL)isFitterThanChromosome:(JASChromosome *)other
+ forTargetSequence:(NSString *)seq
+{
+ NSInteger mine = [self fitnessForTargetSequence:seq];
+ NSInteger theirs = [other fitnessForTargetSequence:seq];
+ return mine > theirs;
+}
+
+#pragma mark - Private methods
+
+- (NSInteger)fitnessForTargetSequence:(NSString *)seq
+{
+ if (!self.cachedOverallFitness)
+ {
+ // The lower the fitness, the less the
+ // chromosome matches the target sequence.
+ // 0 is a perfect match.
+ NSInteger overallFitness = 0, fitness = 0;
+ NSNumber *box = nil;
+ NSUInteger count = seq.length;
+ for (int i = 0; i < count; ++i)
+ {
+ fitness = [self fitnessOfGeneAtIndex:i
+ forTargetSequence:seq];
+ box = [NSNumber numberWithInteger:fitness];
+ [self.fitnessBuffer addObject:box];
+ overallFitness += fitness;
+ }
+ self.cachedOverallFitness =
+ [NSNumber numberWithInteger:overallFitness];
+ }
+ return [self.cachedOverallFitness integerValue];
+}
+
+- (NSInteger)fitnessOfGeneAtIndex:(NSUInteger)geneIndex
+ forTargetSequence:(NSString *)seq
+{
+ unichar target = [seq characterAtIndex:geneIndex];
+ unichar actual = [geneBuffer characterAtIndex:geneIndex];
+ return abs(target - actual) * -1;
+}
+
+- (void)mutate
+{
+ NSInteger delta = RANDOM_MOD(MUTATION_DELTA_MAX);
+
+ // About half the time we should
+ // mutate to a lower character.
+ BOOL negate = RANDOM_MOD(2) == 0;
+ if (negate)
+ delta *= -1;
+
+ // Pick a gene at random to mutate.
+ NSUInteger geneIndex = RANDOM_MOD(self.geneBuffer.length);
+ unichar gene = [self.geneBuffer characterAtIndex:geneIndex];
+
+ // Make sure the mutated character is valid.
+ unichar proposedGene = gene + delta;
+ if (proposedGene < FIRST_CHAR || proposedGene > LAST_CHAR)
+ delta *= -1;
+
+ // Create and apply the mutated gene.
+ unichar value = gene + delta;
+ NSString *mutant = [NSString stringWithFormat:@"%c", value];
+ NSRange range = (NSRange){ geneIndex, 1 };
+ [self.geneBuffer replaceCharactersInRange:range
+ withString:mutant];
+
+ // Dirty the cached fitness value, in case it's already set.
+ self.cachedOverallFitness = nil;
+}
+
+@end
View
29 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosomeARC.h
@@ -0,0 +1,29 @@
+//
+// JASChromosome.h
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface JASChromosomeARC : NSObject
+
+// Returns a copy of this chromosome's genes.
+@property (nonatomic, readonly, strong) NSString *geneSequence;
+
+// Designated initializer.
+- (id)initWithGeneCount:(NSUInteger)count;
++(id) chromosomeWithGeneCount:(NSUInteger)count;
+
+// Creates a new chromosome based on the gene
+// sequences of this chromosome and another one.
+- (JASChromosomeARC *)mateWithChromosome:(JASChromosomeARC *)other;
+
+// Returns YES if this chromosome's fitness is better
+// than the other chromosome's fitness.
+- (BOOL)isFitterThanChromosome:(JASChromosomeARC *)other
+ forTargetSequence:(NSString *)sequence;
+
+@end
View
185 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASChromosomeARC.m
@@ -0,0 +1,185 @@
+//
+// JASChromosomeARC.m
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import "JASChromosomeARC.h"
+
+#define ARC4RANDOM_MAX (0x100000000) // The highest value returned by arc4random()
+#define FIRST_CHAR (32) // ' '
+#define LAST_CHAR (122) // 'Z'
+#define MUTATION_DELTA_MAX (6) // Mutate one gene by no more than +/-5.
+#define MUTATION_RATE (0.20f) // Mutate about 20% of the time
+#define MUTATION_THRESHOLD (ARC4RANDOM_MAX * MUTATION_RATE) // This is used to determine if a mutation should occur.
+#define RANDOM() (arc4random()) // Creates a random positive whole number
+#define RANDOM_MOD(__MOD) (arc4random_uniform(__MOD)) // Creates a random positive whole number no greater than __MOD-1
+
+@interface JASChromosomeARC ()
+@property (nonatomic, strong) NSNumber *cachedOverallFitness;
+@property (nonatomic, strong) NSMutableArray *fitnessBuffer;
+@property (nonatomic, strong) NSMutableString *geneBuffer;
+
+// Calculates the overall fitness of this chromosome's gene sequence,
+// with respect to the target gene sequence.
+- (NSInteger)fitnessForTargetSequence:(NSString *)seq;
+
+// Calculates the fitness of one gene in the chromosome.
+- (NSInteger)fitnessOfGeneAtIndex:(NSUInteger)geneIndex
+ forTargetSequence:(NSString *)seq;
+
+// Performs a random mutation on one gene in the chromosome.
+- (void)mutate;
+@end
+
+
+@implementation JASChromosomeARC
+
+@synthesize cachedOverallFitness;
+@synthesize fitnessBuffer;
+@synthesize geneBuffer;
+
+@dynamic geneSequence;
+- (NSString *)geneSequence
+{
+ return [NSString stringWithString:geneBuffer];
+}
+
++(id) chromosomeWithGeneCount:(NSUInteger)count
+{
+ return [[self alloc] initWithGeneCount:count];
+}
+- (id)initWithGeneCount:(NSUInteger)count
+{
+ self = [super init];
+ if (self)
+ {
+ self.fitnessBuffer = [NSMutableArray arrayWithCapacity:count];
+ self.geneBuffer = [NSMutableString stringWithCapacity:count];
+ for (int geneIndex = 0; geneIndex < count; ++geneIndex)
+ {
+ // Append a random character between ' ' and 'Z'.
+ int value = RANDOM_MOD(LAST_CHAR - FIRST_CHAR);
+ value += FIRST_CHAR;
+ NSString *gene = [NSString stringWithFormat:@"%c", value];
+ [self.geneBuffer appendString:gene];
+ }
+ }
+ return self;
+}
+
+- (JASChromosomeARC *)mateWithChromosome:(JASChromosomeARC *)other
+{
+ // Create an empty chromosome.
+ JASChromosomeARC *child = [[JASChromosomeARC alloc] initWithGeneCount:0];
+
+ // Declare loop variables.
+ NSUInteger count = self.geneBuffer.length;
+ NSNumber *mine, *theirs;
+ JASChromosomeARC *winner;
+ unichar geneValue;
+ NSString *gene;
+
+ // Fill the new chromosome's gene buffer with
+ // the fittest genes from both parents.
+ for (int i = 0; i < count; ++i)
+ {
+ // Get the same gene from both chromosomes.
+ mine = [self.fitnessBuffer objectAtIndex:i];
+ theirs = [other.fitnessBuffer objectAtIndex:i];
+
+ // Determine which chromosome's gene is fitter.
+ winner = [mine integerValue] > [theirs integerValue]
+ ? self
+ : other;
+
+ // Add the winner's gene to the child chromosome.
+ geneValue = [winner.geneBuffer characterAtIndex:i];
+ gene = [NSString stringWithFormat:@"%c", geneValue];
+ [child.geneBuffer appendString:gene];
+ }
+
+ // Sometimes randomly modify the child's gene sequence.
+ if (RANDOM() < MUTATION_THRESHOLD)
+ {
+ [child mutate];
+ }
+
+ return child;
+}
+
+- (BOOL)isFitterThanChromosome:(JASChromosomeARC *)other
+ forTargetSequence:(NSString *)seq
+{
+ NSInteger mine = [self fitnessForTargetSequence:seq];
+ NSInteger theirs = [other fitnessForTargetSequence:seq];
+ return mine > theirs;
+}
+
+#pragma mark - Private methods
+
+- (NSInteger)fitnessForTargetSequence:(NSString *)seq
+{
+ if (!self.cachedOverallFitness)
+ {
+ // The lower the fitness, the less the
+ // chromosome matches the target sequence.
+ // 0 is a perfect match.
+ NSInteger overallFitness = 0, fitness = 0;
+ NSNumber *box = nil;
+ NSUInteger count = seq.length;
+ for (int i = 0; i < count; ++i)
+ {
+ fitness = [self fitnessOfGeneAtIndex:i
+ forTargetSequence:seq];
+ box = [NSNumber numberWithInteger:fitness];
+ [self.fitnessBuffer addObject:box];
+ overallFitness += fitness;
+ }
+ self.cachedOverallFitness =
+ [NSNumber numberWithInteger:overallFitness];
+ }
+ return [self.cachedOverallFitness integerValue];
+}
+
+- (NSInteger)fitnessOfGeneAtIndex:(NSUInteger)geneIndex
+ forTargetSequence:(NSString *)seq
+{
+ unichar target = [seq characterAtIndex:geneIndex];
+ unichar actual = [geneBuffer characterAtIndex:geneIndex];
+ return abs(target - actual) * -1;
+}
+
+- (void)mutate
+{
+ NSInteger delta = RANDOM_MOD(MUTATION_DELTA_MAX);
+
+ // About half the time we should
+ // mutate to a lower character.
+ BOOL negate = RANDOM_MOD(2) == 0;
+ if (negate)
+ delta *= -1;
+
+ // Pick a gene at random to mutate.
+ NSUInteger geneIndex = RANDOM_MOD(self.geneBuffer.length);
+ unichar gene = [self.geneBuffer characterAtIndex:geneIndex];
+
+ // Make sure the mutated character is valid.
+ unichar proposedGene = gene + delta;
+ if (proposedGene < FIRST_CHAR || proposedGene > LAST_CHAR)
+ delta *= -1;
+
+ // Create and apply the mutated gene.
+ unichar value = gene + delta;
+ NSString *mutant = [NSString stringWithFormat:@"%c", value];
+ NSRange range = (NSRange){ geneIndex, 1 };
+ [self.geneBuffer replaceCharactersInRange:range
+ withString:mutant];
+
+ // Dirty the cached fitness value, in case it's already set.
+ self.cachedOverallFitness = nil;
+}
+
+@end
View
23 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgo.h
@@ -0,0 +1,23 @@
+//
+// JASGeneticAlgo.h
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface JASGeneticAlgo : NSObject
+
+// These properties are used only for displaying the results of execution in the UI.
+@property (nonatomic, readonly, assign) NSInteger generations;
+@property (nonatomic, readonly, strong) NSString *result;
+
+// Designated initializer
+- (id)initWithTargetSequence:(NSString *)sequence;
+
+// Runs the genetic algorithm to generate a string that matches the target sequence.
+- (void)execute;
+
+@end
View
153 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgo.m
@@ -0,0 +1,153 @@
+//
+// JASGeneticAlgo.m
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import "JASGeneticAlgo.h"
+#import "JASChromosome.h"
+
+@interface JASGeneticAlgo ()
+
+// Add private setters to public properties
+@property (nonatomic, readwrite, strong) NSString *result;
+@property (nonatomic, readwrite, assign) NSInteger generations;
+
+// Private properties
+@property (nonatomic, strong) NSMutableArray *population;
+@property (nonatomic, copy) NSString *targetSequence;
+
+// Private methods
+- (void)populate;
+- (void)run;
+- (void)breedNextGeneration;
+- (void)shufflePopulation;
+- (void)analyzePopulation;
+
+@end
+
+
+@implementation JASGeneticAlgo
+
+@synthesize generations;
+@synthesize population;
+@synthesize result;
+@synthesize targetSequence;
+
+#define MAX_GENERATIONS 12 // Prevents infinite loops.
+#define POPULATION_SIZE 50 // Must be an even number.
+
+- (id)initWithTargetSequence:(NSString *)sequence
+{
+ self = [super init];
+ if (self)
+ {
+ self.targetSequence = sequence;
+ self.population = [NSMutableArray arrayWithCapacity:POPULATION_SIZE];
+ }
+ return self;
+}
+
+- (void)execute
+{
+ [self populate];
+ [self run];
+}
+
+#pragma mark - Private methods
+
+- (void)populate
+{
+ NSUInteger geneCount = self.targetSequence.length;
+ JASChromosome *chromo;
+ for (int i = 0; i < POPULATION_SIZE; ++i)
+ {
+ chromo = [[JASChromosome alloc] initWithGeneCount:geneCount];
+ [self.population addObject:chromo];
+ [chromo release];
+ }
+}
+
+- (void)run
+{
+ for (self.generations = 0;
+ self.generations < MAX_GENERATIONS && !self.result;
+ self.generations++)
+ {
+ [self breedNextGeneration];
+ [self shufflePopulation];
+ [self analyzePopulation];
+ }
+
+ --self.generations;
+}
+
+- (void)breedNextGeneration
+{
+ // Declare loop variables.
+ NSUInteger index1, index2, deadIndex;
+ JASChromosome *chromo1, *chromo2, *child;
+ NSString *seq = self.targetSequence;
+ BOOL keepFirst;
+ NSUInteger count = self.population.count;
+
+ // Mate each two successive chromosomes and
+ // replace the less fit parent with the child.
+ for (int i = 0; i < count; i += 2)
+ {
+ index1 = i;
+ index2 = i + 1;
+ chromo1 = [self.population objectAtIndex:index1];
+ chromo2 = [self.population objectAtIndex:index2];
+ keepFirst = [chromo1 isFitterThanChromosome:chromo2
+ forTargetSequence:seq];
+ deadIndex = keepFirst ? index2 : index1;
+ child = [chromo1 mateWithChromosome:chromo2];
+ [self.population replaceObjectAtIndex:deadIndex
+ withObject:child];
+ }
+}
+
+- (void)shufflePopulation
+{
+ // Here is my special sauce that makes it all work.
+ // Shuffle the population slightly after each
+ // generation to ensure that the chromosomes have
+ // a chance to mate with multiple partners.
+ JASChromosome *last = [[self.population lastObject] retain];
+ [population removeLastObject];
+ [population insertObject:last atIndex:0];
+ [last release];
+}
+
+- (void)analyzePopulation
+{
+ // Find the fittest chromosome in the population
+ // and see if matches the target sequence.
+ JASChromosome *champion = nil;
+ NSString *seq = self.targetSequence;
+ for (JASChromosome *contender in self.population)
+ {
+ if (!champion ||
+ [contender isFitterThanChromosome:champion
+ forTargetSequence:seq])
+ {
+ champion = contender;
+ }
+ }
+ NSString *fittest = champion.geneSequence;
+ BOOL matchesTarget = [fittest isEqualToString:seq];
+ if (matchesTarget)
+ {
+ self.result = fittest;
+ //NSLog(@"Matched the target sequence during generation #%ld", (long)self.generations);
+ }
+ else
+ {
+ //NSLog(@"Fittest sequence for generation #%ld: %@", (long)self.generations, fittest);
+ }
+}
+
+@end
View
23 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgoARC.h
@@ -0,0 +1,23 @@
+//
+// JASGeneticAlgo.h
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface JASGeneticAlgoARC : NSObject
+
+// These properties are used only for displaying the results of execution in the UI.
+@property (nonatomic, readonly, assign) NSInteger generations;
+@property (nonatomic, readonly, strong) NSString *result;
+
+// Designated initializer
+- (id)initWithTargetSequence:(NSString *)sequence;
+
+// Runs the genetic algorithm to generate a string that matches the target sequence.
+- (void)execute;
+
+@end
View
152 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/JASGeneticAlgoARC.m
@@ -0,0 +1,152 @@
+//
+// JASGeneticAlgoARC.m
+// SimpleGeneticAlgo
+//
+// Created by Joshua Smith on 4/3/12.
+// Copyright (c) 2012 iJoshSmith. All rights reserved.
+//
+
+#import "JASGeneticAlgoARC.h"
+#import "JASChromosomeARC.h"
+
+@interface JASGeneticAlgoARC ()
+
+// Add private setters to public properties
+@property (nonatomic, readwrite, strong) NSString *result;
+@property (nonatomic, readwrite, assign) NSInteger generations;
+
+// Private properties
+@property (nonatomic, strong) NSMutableArray *population;
+@property (nonatomic, copy) NSString *targetSequence;
+
+// Private methods
+- (void)populate;
+- (void)run;
+- (void)breedNextGeneration;
+- (void)shufflePopulation;
+- (void)analyzePopulation;
+
+@end
+
+
+@implementation JASGeneticAlgoARC
+
+@synthesize generations;
+@synthesize population;
+@synthesize result;
+@synthesize targetSequence;
+
+#define MAX_GENERATIONS 12 // Prevents infinite loops.
+#define POPULATION_SIZE 50 // Must be an even number.
+
+- (id)initWithTargetSequence:(NSString *)sequence
+{
+ self = [super init];
+ if (self)
+ {
+ self.targetSequence = sequence;
+ self.population =
+ [NSMutableArray arrayWithCapacity:POPULATION_SIZE];
+ }
+ return self;
+}
+
+- (void)execute
+{
+ [self populate];
+ [self run];
+}
+
+#pragma mark - Private methods
+
+- (void)populate
+{
+ NSUInteger geneCount = self.targetSequence.length;
+ JASChromosomeARC *chromo;
+ for (int i = 0; i < POPULATION_SIZE; ++i)
+ {
+ chromo = [JASChromosomeARC chromosomeWithGeneCount:geneCount];
+ [self.population addObject:chromo];
+ }
+}
+
+- (void)run
+{
+ for (self.generations = 0;
+ self.generations < MAX_GENERATIONS && !self.result;
+ self.generations++)
+ {
+ [self breedNextGeneration];
+ [self shufflePopulation];
+ [self analyzePopulation];
+ }
+
+ --self.generations;
+}
+
+- (void)breedNextGeneration
+{
+ // Declare loop variables.
+ NSUInteger index1, index2, deadIndex;
+ JASChromosomeARC *chromo1, *chromo2, *child;
+ NSString *seq = self.targetSequence;
+ BOOL keepFirst;
+ NSUInteger count = self.population.count;
+
+ // Mate each two successive chromosomes and
+ // replace the less fit parent with the child.
+ for (int i = 0; i < count; i += 2)
+ {
+ index1 = i;
+ index2 = i + 1;
+ chromo1 = [self.population objectAtIndex:index1];
+ chromo2 = [self.population objectAtIndex:index2];
+ keepFirst = [chromo1 isFitterThanChromosome:chromo2
+ forTargetSequence:seq];
+ deadIndex = keepFirst ? index2 : index1;
+ child = [chromo1 mateWithChromosome:chromo2];
+ [self.population replaceObjectAtIndex:deadIndex
+ withObject:child];
+ }
+}
+
+- (void)shufflePopulation
+{
+ // Here is my special sauce that makes it all work.
+ // Shuffle the population slightly after each
+ // generation to ensure that the chromosomes have
+ // a chance to mate with multiple partners.
+ JASChromosomeARC *last = [self.population lastObject];
+ [population removeLastObject];
+ [population insertObject:last atIndex:0];
+}
+
+- (void)analyzePopulation
+{
+ // Find the fittest chromosome in the population
+ // and see if matches the target sequence.
+ JASChromosomeARC *champion = nil;
+ NSString *seq = self.targetSequence;
+ for (JASChromosomeARC *contender in self.population)
+ {
+ if (!champion ||
+ [contender isFitterThanChromosome:champion
+ forTargetSequence:seq])
+ {
+ champion = contender;
+ }
+ }
+ NSString *fittest = champion.geneSequence;
+ BOOL matchesTarget = [fittest isEqualToString:seq];
+ if (matchesTarget)
+ {
+ self.result = fittest;
+ //NSLog(@"Matched the target sequence during generation #%ld", (long)self.generations);
+ }
+ else
+ {
+ //NSLog(@"Fittest sequence for generation #%ld: %@", (long)self.generations, fittest);
+ }
+}
+
+@end
View
23 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/MRCTests.h
@@ -0,0 +1,23 @@
+//
+// MRCTests.h
+// Cocos2D-ARC-Performance-Test
+//
+// Created by Steffen Itterheim on 20.03.13.
+//
+//
+
+#import <Foundation/Foundation.h>
+
+@interface MRCTests : NSObject
+
+@property (nonatomic, copy) NSString* string;
+
++(id) mrcTests;
+-(void) createAutoreleaseObject;
+-(void) createAllocInitObject;
+-(void) messageThatDoesNothing;
+-(CCNode*) createAndReturnAutoreleaseObject;;
+-(BOOL) data:(NSData*)data containsCString:(char *)cmp;
+-(void) runGeneticAlgorithm;
+
+@end
View
90 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/MRCTests.m
@@ -0,0 +1,90 @@
+//
+// MRCTests.m
+// Cocos2D-ARC-Performance-Test
+//
+// Created by Steffen Itterheim on 20.03.13.
+//
+//
+
+#import "cocos2d.h"
+#import "MRCTests.h"
+#import "JASGeneticAlgo.h"
+
+@implementation MRCTests
+
++(id) mrcTests
+{
+ return [[[self alloc] init] autorelease];
+}
+
+-(void) dealloc
+{
+ //NSLog(@"MRC Test dealloc");
+ [super dealloc]; // this line is illegal under ARC
+}
+
+-(void) createAutoreleaseObject
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ CCNode* test = [CCNode node];
+ test = nil;
+
+ [pool release];
+}
+
+-(void) createAllocInitObject
+{
+ CCNode* test = [[CCNode alloc] init];
+ [test release];
+ test = nil;
+}
+
+-(CCNode*) createAndReturnAutoreleaseObject
+{
+ return [CCNode node];
+}
+
+-(void) messageThatDoesNothing
+{
+}
+
+// code from:
+// http://iphonedevelopment.blogspot.de/2008/04/root-of-all-evil-introduction-to.html
+-(BOOL) data:(NSData*)data containsCString:(char *)cmp
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ BOOL retval = NO;
+ NSUInteger offset = 0;
+ char * byte;
+ const char * bytes = [data bytes];
+
+ while (offset < [data length])
+ {
+ byte = (char *)bytes;
+
+ NSString * checkString = [NSString stringWithCString:byte encoding:NSUTF8StringEncoding];
+ if ([checkString isEqualToString:[NSString stringWithCString:cmp encoding:NSUTF8StringEncoding]])
+ {
+ retval = YES;
+ break;
+ }
+
+ offset++;
+ }
+
+ [pool release];
+ return retval;
+}
+
+-(void) runGeneticAlgorithm
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ NSString* sequence = @"lks89Ü?c§cngW3d432d7cf143497fb5a95b280f873b16iysöl5cöä#ke2ß0B% ()=BÄ´Qyaix4@\nElapsou5ö8o7 5V4*j6ß71655b7c7b6cb41128dffc046773acfbc8w3y,ic;9uwo9ly8WV)+:.573j 4jpew Q'C)96ß#8m)$VNwv49";
+ JASGeneticAlgo *algo = [[JASGeneticAlgo alloc] initWithTargetSequence:sequence];
+ [algo execute];
+ [pool release];
+}
+
+@end
View
98 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester.h
@@ -0,0 +1,98 @@
+//
+// PerfTester
+//
+// Copyright 2007-2008 Mike Ash
+// http://mikeash.com/pyblog/performance-comparisons-of-common-operations.html
+// http://mikeash.com/pyblog/performance-comparisons-of-common-operations-leopard-edition.html
+// http://mikeash.com/pyblog/performance-comparisons-of-common-operations-iphone-edition.html
+// Copyright 2010 Manomio / Stuart Carnie (iOS port)
+// http://aussiebloke.blogspot.com/2010/01/micro-benchmarking-2nd-3rd-gen-iphones.html
+// Copyright 2011 Steffen Itterheim (Improvements, Cocos2D & ARC Tests)
+// http://www.learn-cocos2d.com/blog
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#import "cocos2d.h"
+
+@class ARCTests;
+@class MRCTests;
+
+typedef enum
+{
+ kkPerformanceTestARCvsMRC_Messaging,
+ kkPerformanceTestARCvsMRC_AllocInit,
+ kkPerformanceTestARCvsMRC_Autorelease,
+ kkPerformanceTestARCvsMRC_Algorithm,
+
+ kkPerformanceTestArithmetic,
+ kkPerformanceTestArray,
+ kkPerformanceTestMemory,
+ KKPerformanceTestObjectCreation,
+ KKPerformanceTestTextureLoading,
+ KKPerformanceTestMessaging,
+ KKPerformanceTestIO,
+ kkPerformanceTestMisc,
+ kkPerformanceTestNodeHierarchy,
+ kkPerformanceTestObjectCompare,
+} KKPerformanceTestType;
+
+typedef struct { const char *name; SEL sel; } Test;
+
+#define BEGIN( count ) \
+int iters = count; \
+int i; \
+[self beginTest]; \
+for( i = 1; i <= iters; i++ ) {
+
+#define END() \
+} \
+[self endTestWithIterations: iters];
+
+@interface PerfTester : NSObject
+{
+ uint64_t mStartTime, mEndTime;
+ int mIterations;
+ double totalRunningTime;
+
+ BOOL quickTest;
+ NSString *logFile;
+
+ UIWebView* webView;
+
+ int k1000MMIterationTestCount;
+ int k100MMIterationTestCount;
+ int k10MMIterationTestCount;
+ int k1MMIterationTestCount;
+ int k100KIterationTestCount;
+ int k10KIterationTestCount;
+ int k1KIterationTestCount;
+ int k100IterationTestCount;
+ int k10IterationTestCount;
+
+ int intRes;
+ float floatRes;
+ double doubleRes;
+ double doubleDiv;
+
+ __strong ARCTests* arcTest;
+ __strong MRCTests* mrcTest;
+}
+
+@property (nonatomic) BOOL quickTest;
+@property (nonatomic, readonly) UIWebView* webView;
+
+// for internal use only
+- (void)beginTest;
+- (void)endTestWithIterations: (int)iters;
+
+// external API
+-(void) test:(KKPerformanceTestType)type;
+-(void) printResultsToStandardOutput;
+-(void) showResultsInView:(UIView*)view;
+
+
+-(void) setupARCvsMRCTests;
+
+@end
+
View
588 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester.mm
@@ -0,0 +1,588 @@
+//
+// PerfTester
+//
+// Copyright 2007-2008 Mike Ash
+// http://mikeash.com/pyblog/performance-comparisons-of-common-operations.html
+// http://mikeash.com/pyblog/performance-comparisons-of-common-operations-leopard-edition.html
+// http://mikeash.com/pyblog/performance-comparisons-of-common-operations-iphone-edition.html
+// Copyright 2010 Manomio / Stuart Carnie (iOS port)
+// http://aussiebloke.blogspot.com/2010/01/micro-benchmarking-2nd-3rd-gen-iphones.html
+// Copyright 2011 Steffen Itterheim (Improvements, Cocos2D & ARC Tests)
+// http://www.learn-cocos2d.com/blog
+//
+
+
+#import <mach/mach_time.h>
+
+#import "PerfTester.h"
+#import "ARCTests.h"
+#import "MRCTests.h"
+
+@implementation PerfTester
+
+@synthesize quickTest, webView;
+
+-(void) setQuickTest:(BOOL)quick
+{
+ quickTest = quick;
+ NSLog(@"Quick Testing is %@.", quickTest ? @"ON" : @"OFF");
+}
+
+-(id) init
+{
+ if ((self = [super init]))
+ {
+ NSLog(@"Starting tests ...");
+
+ // clean previous log
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentsDirectory = [paths objectAtIndex:0];
+ logFile = [documentsDirectory stringByAppendingPathComponent:@"log.html"];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:logFile])
+ {
+ [[NSFileManager defaultManager] removeItemAtPath:logFile error:nil];
+ }
+ }
+ return self;
+}
+
+struct Result
+{
+ int iterations;
+ double totalDuration;
+ double singleIterationNanosec;
+};
+
+- (struct Result)_timeForSelector: (SEL)sel
+{
+ struct mach_timebase_info tbinfo;
+ mach_timebase_info( &tbinfo );
+
+ mStartTime = mEndTime = 0;
+
+ NSAssert1([self respondsToSelector:sel], @"PerfTester class does not implement selector: %@", NSStringFromSelector(sel));
+
+ @autoreleasepool {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+ [self performSelector: sel];
+#pragma clang diagnostic pop
+ }
+
+ uint64_t duration = mEndTime - mStartTime;
+ double floatDuration = duration * tbinfo.numer / tbinfo.denom;
+
+ struct Result result = {
+ mIterations,
+ floatDuration / 1000000000.0,
+ floatDuration / mIterations
+ };
+ return result;
+}
+
+-(void) setupARCvsMRCTests
+{
+ if (arcTest == nil)
+ {
+ arcTest = [ARCTests arcTests];
+ }
+ if (mrcTest == nil)
+ {
+ mrcTest = [MRCTests mrcTests];
+ }
+}
+
+- (void)test:(KKPerformanceTestType)testType
+{
+ [self setupARCvsMRCTests];
+
+ if (quickTest)
+ {
+ k1000MMIterationTestCount = 100000000;
+ k100MMIterationTestCount = 10000000;
+ k10MMIterationTestCount = 100000;
+ k1MMIterationTestCount = 10000;
+ k100KIterationTestCount = 1000;
+ k10KIterationTestCount = 100;
+ k1KIterationTestCount = 20;
+ k100IterationTestCount = 8;
+ k10IterationTestCount = 4;
+ }
+ else
+ {
+ k1000MMIterationTestCount = 1000000000;
+ k100MMIterationTestCount = 100000000;
+ k10MMIterationTestCount = 10000000;
+ k1MMIterationTestCount = 1000000;
+ k100KIterationTestCount = 100000;
+ k10KIterationTestCount = 10000;
+ k1KIterationTestCount = 1000;
+ k100IterationTestCount = 100;
+ k10IterationTestCount = 10;
+ }
+
+ Test testSels[100];
+
+ // TODO:
+ /*
+ add, subtract
+ property vs public instance variable
+ more on array performance
+ */
+
+ switch (testType)
+ {
+ case kkPerformanceTestARCvsMRC_Messaging:
+ {
+ Test mytestSels[] = {
+ { "ARC: Message Send to Object\0", @selector( testMessageSendObjectARC ), },
+ { "MRC: Message Send to Object\0", @selector( testMessageSendObjectMRC ), },
+ { "ARC: Assign (nonatomic, copy) property\0", @selector( testAssignCopyPropertyARC ), },
+ { "MRC: Assign (nonatomic, copy) property\0", @selector( testAssignCopyPropertyMRC ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestARCvsMRC_Algorithm:
+ {
+ Test mytestSels[] = {
+ { "ARC: Unoptimized Contains String algorithm\0", @selector( testUnoptimizedContainsStringAlgorithmARC ), },
+ { "MRC: Unoptimized Contains String algorithm\0", @selector( testUnoptimizedContainsStringAlgorithmMRC ), },
+ { "ARC: genetic algorithm\0", @selector( testGeneticAlgorithmARC ), },
+ { "MRC: genetic algorithm\0", @selector( testGeneticAlgorithmMRC ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestARCvsMRC_AllocInit:
+ {
+ Test mytestSels[] = {
+ { "ARC: Create Alloc/Init Object\0", @selector( testInternalCreateAllocInitObjectARC ), },
+ { "MRC: Create Alloc/Init Object\0", @selector( testInternalCreateAllocInitObjectMRC ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestARCvsMRC_Autorelease:
+ {
+ Test mytestSels[] = {
+ { "ARC: Create Autorelease Object\0", @selector( testInternalCreateAutoreleaseObjectARC ), },
+ { "MRC: Create Autorelease Object\0", @selector( testInternalCreateAutoreleaseObjectMRC ), },
+ { "ARC: Create & Return Autorelease Object\0", @selector( testCreateAndReturnAutoreleaseObjectARC ), },
+ { "MRC: Create & Return Autorelease Object\0", @selector( testCreateAndReturnAutoreleaseObjectMRC ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+
+
+
+ case kkPerformanceTestArithmetic:
+ {
+ Test mytestSels[] = {
+ { "Integer multiplication\0", @selector( testIntMultiplication ), },
+ { "Float multiplication\0", @selector( testFloatMultiplication ), },
+ { "Double multiplication\0", @selector( testDoubleMultiplication ), },
+ { "Integer division\0", @selector( testIntDivision ), },
+ { "Float division\0", @selector( testFloatDivision ), },
+ { "Double division\0", @selector( testDoubleDivision ), },
+ { "Float division with int conversion\0", @selector( testFloatConversionDivision ), },
+ { "Double division with int conversion\0", @selector( testDoubleConversionDivision ), },
+ { "Float square root\0", @selector( testFloatSquareRoot ), },
+ { "Double square root\0", @selector( testDoubleSquareRoot ), },
+ { "Accelerometer Highpass filter\0", @selector( testHighPassFilter ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestArray:
+ {
+ Test mytestSels[] = {
+ { "NSMutableArray insertObject: atIndex:0\0", @selector( testNSMutableArrayWithCapacityInsertObjectAtIndex0), },
+ { "CCArray insertObject: atIndex:0\0", @selector( testCCArrayWithCapacityInsertObjectAtIndex0), },
+ { "NSMutableArray insertObject: atIndex:random\0", @selector( testNSMutableArrayWithCapacityInsertObjectAtIndexHalfCount), },
+ { "CCArray insertObject: atIndex:random\0", @selector( testCCArrayWithCapacityInsertObjectAtIndexHalfCount), },
+ { "CCArray removeObjectAtIndex\0", @selector( testCCArrayRemoveObjectAtIndexAndAdd), },
+ { "NSMutableArray removeObjectAtIndex\0", @selector( testNSMutableArrayRemoveObjectAtIndexAndAdd), },
+ { "CCArray removeLastObject\0", @selector( testCCArrayRemoveLastObjectAndAdd), },
+ { "NSMutableArray removeLastObject\0", @selector( testNSMutableArrayRemoveLastObjectAndAdd), },
+ { "CCArray containsObject\0", @selector( testCCArrayContainsObject), },
+ { "NSMutableArray containsObject\0", @selector( testNSMutableArrayContainsObject), },
+ { "CCArray add/removeObjectsInArray\0", @selector( testCCArrayRemoveAndAddObjectsFromArray), },
+ { "NSMutableArray add/removeObjectsInArray\0", @selector( testNSMutableArrayRemoveAndAddObjectsFromArray), },
+ { "CCArray exchangeObjectAtIndex\0", @selector( testCCArrayExchangeObjectAtIndex), },
+ { "NSMutableArray exchangeObjectAtIndex\0", @selector( testNSMutableArrayExchangeObjectAtIndex), },
+ { "CCArray indexOfObject\0", @selector( testCCArrayIndexOfObject), },
+ { "NSMutableArray indexOfObject\0", @selector( testNSMutableArrayIndexOfObject), },
+ { "CCArray makeObjectsPerformSelector\0", @selector( testCCArrayMakeObjectsPerformSelector), },
+ { "NSMutableArray makeObjectsPerformSelector\0", @selector( testNSMutableArrayMakeObjectsPerformSelector), },
+ { "CCArray makeObjectsPerformSelector withObject\0", @selector( testCCArrayMakeObjectsPerformSelectorWithObject), },
+ { "NSMutableArray makeObjectsPerformSelector withObject\0", @selector( testNSMutableArrayMakeObjectsPerformSelectorWithObject), },
+ { "CCArray enumeration\0", @selector( testCCArrayEnumeration), },
+ { "CCArray fast enumeration\0", @selector( testCCArrayFastEnumeration), },
+ { "NSMutableArray enumeration\0", @selector( testNSMutableArrayEnumeration), },
+ { "NSMutableArray fast enumeration\0", @selector( testNSMutableArrayFastEnumeration), },
+ { "NSMutableArray addObject:\0", @selector( testNSMutableArrayAddObject), },
+ { "CCArray addObject:\0", @selector( testCCArrayAddObject), },
+ { "NSMutableArray withCapacity addObject:\0", @selector( testNSMutableArrayWithCapacityAddObject), },
+ { "CCArray withCapacity addObject:\0", @selector( testCCArrayWithCapacityAddObject), },
+ { "NSMutableArray objectAtIndex:\0", @selector( testObjCObjectAtIndex), },
+ { "CCArray objectAtIndex:\0", @selector( testCCArrayObjectAtIndex), },
+ { "CFArray GetValueAtIndex\0", @selector( testCFObjectAtIndex), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestMemory:
+ {
+ Test mytestSels[] = {
+ { "16 byte malloc/free\0", @selector( testSmallMallocFree ), },
+ { "16MB malloc/free\0", @selector( testLargeMallocFree ), },
+ { "16 byte memcpy\0", @selector( testSmallMemcpy ), },
+ { "1MB memcpy\0", @selector( testLargeMemcpy ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case KKPerformanceTestObjectCreation:
+ {
+ Test mytestSels[] = {
+ { "CCSprite GCD alloc/initWithFile/release\0", @selector( testCCSpriteWithFileCreationConcurrentlyWithGCD ), },
+ { "CCSprite alloc/initWithFile/release\0", @selector( testCCSpriteWithFileCreation ), },
+
+ { "CCTMXTiledMap small alloc/init/release\0", @selector( testCCTMXTiledMapSmallCreation ), },
+ { "CCTMXTiledMap large alloc/init/release\0", @selector( testCCTMXTiledMapLargeCreation ), },
+ //{ "CCTMXTiledMap gigantic alloc/init/release\0", @selector( testCCTMXTiledMapGiganticCreation ), },
+ { "CCParticleSystemQuad 25 particles alloc/init/release\0", @selector( testCCParticleSystemQuadSmallCreation ), },
+ { "CCParticleSystemQuad 250 particles alloc/init/release\0", @selector( testCCParticleSystemQuadLargeCreation ), },
+ { "NSAutoreleasePool alloc/init/release\0", @selector( testPoolCreation ), },
+ { "NSObject alloc/init/release\0", @selector( testNSObjectCreation ), },
+ { "CCNode alloc/init/release\0", @selector( testCCNodeCreation ), },
+ { "CCLabelBMFont alloc/initWithString/release\0", @selector( testCCLabelBMFontWithStringCreation ), },
+ { "CCLabelTTF alloc/initWithString/release\0", @selector( testCCLabelTTFWithStringCreation ), },
+ { "CCMoveTo alloc/init/release\0", @selector( testCCMoveToCreation ), },
+ { "CCSequence alloc/initOne/release\0", @selector( testCCSequenceCreation ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+
+ case KKPerformanceTestTextureLoading:
+ {
+ Test mytestSels[] = {
+ /*
+ { "PVRTC2_no-alpha.pvr\0", @selector( testLoadTexture_PVRTC2_no_alpha_pvr ), },
+ { "PVRTC2_no-alpha.pvr.ccz\0", @selector( testLoadTexture_PVRTC2_no_alpha_pvrccz ), },
+ { "PVRTC2_no-alpha.pvr.gz\0", @selector( testLoadTexture_PVRTC2_no_alpha_pvrgz ), },
+ { "PVRTC4_no-alpha.pvr\0", @selector( testLoadTexture_PVRTC4_no_alpha_pvr ), },
+ { "PVRTC4_no-alpha.pvr.ccz\0", @selector( testLoadTexture_PVRTC4_no_alpha_pvrccz ), },
+ { "PVRTC4_no-alpha.pvr.gz\0", @selector( testLoadTexture_PVRTC4_no_alpha_pvrgz ), },
+ */
+
+ { "PVRTC2.pvr\0", @selector( testLoadTexture_PVRTC2_pvr ), },
+ { "PVRTC2.pvr.ccz\0", @selector( testLoadTexture_PVRTC2_pvrccz ), },
+ { "PVRTC2.pvr.gz\0", @selector( testLoadTexture_PVRTC2_pvrgz ), },
+ { "PVRTC4.pvr\0", @selector( testLoadTexture_PVRTC4_pvr ), },
+ { "PVRTC4.pvr.ccz\0", @selector( testLoadTexture_PVRTC4_pvrccz ), },
+ { "PVRTC4.pvr.gz\0", @selector( testLoadTexture_PVRTC4_pvrgz ), },
+
+ { "RGB565.jpg\0", @selector( testLoadTexture_RGB565_jpg ), },
+ { "RGB565.png\0", @selector( testLoadTexture_RGB565_png ), },
+ { "RGB565.pvr\0", @selector( testLoadTexture_RGB565_pvr ), },
+ { "RGB565.pvr.ccz\0", @selector( testLoadTexture_RGB565_pvrccz ), },
+ { "RGB565.pvr.gz\0", @selector( testLoadTexture_RGB565_pvrgz ), },
+
+ { "RGBA4444.jpg\0", @selector( testLoadTexture_RGBA4444_jpg ), },
+ { "RGBA4444.png\0", @selector( testLoadTexture_RGBA4444_png ), },
+ { "RGBA4444.pvr\0", @selector( testLoadTexture_RGBA4444_pvr ), },
+ { "RGBA4444.pvr.ccz\0", @selector( testLoadTexture_RGBA4444_pvrccz ), },
+ { "RGBA4444.pvr.gz\0", @selector( testLoadTexture_RGBA4444_pvrgz ), },
+
+ { "RGBA5551.jpg\0", @selector( testLoadTexture_RGBA5551_jpg ), },
+ { "RGBA5551.png\0", @selector( testLoadTexture_RGBA5551_png ), },
+ { "RGBA5551.pvr\0", @selector( testLoadTexture_RGBA5551_pvr ), },
+ { "RGBA5551.pvr.ccz\0", @selector( testLoadTexture_RGBA5551_pvrccz ), },
+ { "RGBA5551.pvr.gz\0", @selector( testLoadTexture_RGBA5551_pvrgz ), },
+
+ { "RGBA8888.jpg\0", @selector( testLoadTexture_RGBA8888_jpg ), },
+ { "RGBA8888.png\0", @selector( testLoadTexture_RGBA8888_png ), },
+ { "RGBA8888.pvr\0", @selector( testLoadTexture_RGBA8888_pvr ), },
+ { "RGBA8888.pvr.ccz\0", @selector( testLoadTexture_RGBA8888_pvrccz ), },
+ { "RGBA8888.pvr.gz\0", @selector( testLoadTexture_RGBA8888_pvrgz ), },
+
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case KKPerformanceTestMessaging:
+ {
+ Test mytestSels[] = {
+ { "ObjC class nonatomic property message send\0", @selector( testPrivateVariableReadWrite ), },
+ { "ObjC class nonatomic property dot notation\0", @selector( testPrivateVariableReadWriteProperty ), },
+ { "ObjC class atomic property message send\0", @selector( testPrivateVariableReadWriteAtomic ), },
+ { "ObjC class atomic property dot notation\0", @selector( testPrivateVariableReadWriteAtomicProperty ), },
+ { "ObjC class @public variable\0", @selector( testPublicVariableReadWrite ), },
+
+ { "Objective-C NSArray message send\0", @selector( testMessagingArray ), },
+ { "Objective-C CCArray message send\0", @selector( testMessagingCCArray ), },
+ { "Objective-C NSArray enumerateWithBlock msg send\0", @selector( testMessagingArrayUsingBlock ), },
+ { "Objective-C NSArray enumerateWithBlock concurrent msg send\0", @selector( testMessagingArrayUsingBlockConcurrent ), },
+ //{ "Objective-C CCArray enumerateWithBlock msg send\0", @selector( testMessagingCCArrayUsingBlock ), },
+ { "Objective-C NSArray makeObjectsPerformSelector\0", @selector( testMessagingArrayMakeObjectsPerformSelector ), },
+ { "Objective-C CCArray makeObjectsPerformSelector\0", @selector( testMessagingCCArrayMakeObjectsPerformSelector ), },
+ { "Objective-C message send\0", @selector( testMessaging ), },
+ { "Objective-C performSelector\0", @selector( testMessagingPerformSelector ), },
+ //{ "Objective-C performSelector cached\0", @selector( testMessagingPerformSelectorCached ), },
+ { "NSInvocation message send\0", @selector( testNSInvocation ), },
+ { "IMP-cached message send\0", @selector( testIMPCachedMessaging ), },
+ { "C++ virtual method call\0", @selector( testCPPVirtualCall ), },
+ { "C++ cached virtual method call\0", @selector( testCPPCachedVirtualCall ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case KKPerformanceTestIO:
+ {
+ Test mytestSels[] = {
+ { "Write 16-byte file\0", @selector( testWriteSmallFile ), },
+ { "Write 16-byte file (atomic)\0", @selector( testWriteSmallFileAtomic ), },
+ { "Write 16MB file\0", @selector( testWriteLargeFile ), },
+ { "Write 16MB file (atomic)\0", @selector( testWriteLargeFileAtomic ), },
+ { "Read 16-byte file\0", @selector( testReadSmallFile ), },
+ { "Read 16MB file\0", @selector( testReadLargeFile ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestMisc:
+ {
+ Test mytestSels[] = {
+ { "pthread create/join\0", @selector( testSpawnThread ), },
+ { "Zero-second delayed perform\0", @selector( testDelayedPerform ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestNodeHierarchy:
+ {
+ Test mytestSels[] = {
+ { "reorderChild w/ 10 Nodes\0", @selector( testReorderChild_FewNodes ), },
+ { "reorderChild w/ 100 Nodes\0", @selector( testReorderChild_MediumNodes ), },
+ { "reorderChild w/ 500 Nodes\0", @selector( testReorderChild_ManyNodes ), },
+ { "reorderChild w/ 2,500 Nodes\0", @selector( testReorderChild_WayTooManyNodes ), },
+
+ { "addChild with tag\0", @selector( testFirst_AddChildWithTag ), },
+ { "getChildByTag w/ 10 Nodes\0", @selector( testGetChildByTag_FewNodes ), },
+ { "getChildByTag w/ 100 Nodes\0", @selector( testGetChildByTag_MediumNodes ), },
+ { "getChildByTag w/ 500 Nodes\0", @selector( testGetChildByTag_ManyNodes ), },
+ { "getChildByTag w/ 2,500 Nodes\0", @selector( testGetChildByTag_WayTooManyNodes ), },
+ { "removeChildByTag\0", @selector( testLast_RemoveChildByTagWithCleanup ), },
+
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ case kkPerformanceTestObjectCompare:
+ {
+ Test mytestSels[] = {
+ { "NSObject hash\0", @selector( testObjectHash ), },
+ { "NSString hash\0", @selector( testStringHash ), },
+ { "NSObject isEqual\0", @selector( testPointerIsEqual ), },
+ { "NSObject is not Equal\0", @selector( testPointerIsEqualFail ), },
+ { "isMemberOfClass\0", @selector( testObjectIsMemberOfClass ), },
+ { "isMemberOfClass, class cached\0", @selector( testObjectIsMemberOfClassOptimized ), },
+ { "isKindOfClass\0", @selector( testObjectIsKindOfClass ), },
+ { "isKindOfClass, class cached\0", @selector( testObjectIsKindOfClassOptimized ), },
+ { "is not MemberOfClass\0", @selector( testObjectIsMemberOfClassFail ), },
+ { "is not MemberOfClass, class cached\0", @selector( testObjectIsMemberOfClassOptimizedFail ), },
+ { "is not KindOfClass\0", @selector( testObjectIsKindOfClassFail ), },
+ { "is not KindOfClass, class cached\0", @selector( testObjectIsKindOfClassOptimizedFail ), },
+ { "NSString isEqual\0", @selector( testStringCompareIsEqual ), },
+ { "NSString is not Equal\0", @selector( testStringCompareIsEqualFail ), },
+ { "NSString isEqualToString\0", @selector( testStringCompareIsEqualToString ), },
+ { "NSString is not EqualToString\0", @selector( testStringCompareIsEqualToStringFail ), },
+ { nil, NULL }
+ };
+ memcpy(testSels, mytestSels, sizeof(mytestSels));
+ break;
+ }
+ }
+
+ NSMutableString *str = [NSMutableString string];
+ switch (testType)
+ {
+ case kkPerformanceTestARCvsMRC_Messaging:
+ [str appendString:@"<h4>ARC vs MRC: Messaging Tests</h4>"];
+ break;
+ case kkPerformanceTestARCvsMRC_AllocInit:
+ [str appendString:@"<h4>ARC vs MRC: Alloc/Init Tests</h4>"];
+ break;
+ case kkPerformanceTestARCvsMRC_Autorelease:
+ [str appendString:@"<h4>ARC vs MRC: Autorelease Tests</h4>"];
+ break;
+ case kkPerformanceTestARCvsMRC_Algorithm:
+ [str appendString:@"<h4>ARC vs MRC: Algorithm Tests</h4>"];
+ break;
+ case kkPerformanceTestArithmetic:
+ [str appendString:@"<h4>Arithmetic Tests</h4>Simple calculations done frequently in an app, using various data types."];
+ break;
+ case kkPerformanceTestArray:
+ [str appendString:@"<h4>Array Tests</h4>Testing Cocos2D's CCArray performance against regular NSMutableArray."];
+ break;
+ case kkPerformanceTestMemory:
+ [str appendString:@"<h4>Memory Tests</h4>Allocating and releasing memory."];
+ break;
+ case KKPerformanceTestObjectCreation:
+ [str appendString:@"<h4>Object Creation</h4>These tests tell you how long it takes to allocate memory, \
+ initialize the object, and deallocate it. The longer this takes for an object, the higher the chance that \
+ doing this during gameplay will negatively affect performance. Note that <strong>these tests do not give any indication \
+ whatsoever of the runtime/rendering performance</strong> of these objects."];
+ break;
+ case KKPerformanceTestTextureLoading:
+ [str appendString:@"<h4>Loading Textures</h4>Time it takes to load and unload the same 1024x1024 texture using a variety of different image file formats, compression and color bit depths."];
+ break;
+ case KKPerformanceTestMessaging:
+ [str appendString:@"<h4>Messaging / Function Calls</h4>Low-level overhead for calling C++ functions respectively sending Objective-C messages in various ways."];
+ break;
+ case KKPerformanceTestIO:
+ [str appendString:@"<h4>File IO</h4>"];
+ break;
+ case kkPerformanceTestMisc:
+ [str appendString:@"<h4>Miscellaneous Tests</h4>"];
+ break;
+ case kkPerformanceTestNodeHierarchy:
+ [str appendString:@"<h4>Node Hierarchy (children)</h4>The performance of functions that act on the node hierarchy (children list) depends heavily on the number of children."];
+ break;
+ case kkPerformanceTestObjectCompare:
+ [str appendString:@"<h4>Object Comparison</h4>Compare objects with various methods, and testing if it makes any difference if the test fails (mismatch) or succeeds (match)."];
+ break;
+ }
+
+ doubleDiv = 42.3;
+
+ mIterations = 100000000;
+ if (quickTest == NO) {
+ mIterations *= 10;
+ }
+
+ [self _timeForSelector: @selector( testNothing )];
+
+ NSNumberFormatter* nf = [[NSNumberFormatter alloc] init];
+ [nf setMaximumFractionDigits:0];
+ [nf setNumberStyle:NSNumberFormatterDecimalStyle];
+
+ NSMutableArray *resultsArray = [NSMutableArray array];
+ int i;
+ for( i = 0; testSels[i].name; i++ )
+ {
+ NSString* name = [NSString stringWithCString:testSels[i].name encoding:NSUTF8StringEncoding];
+ NSLog( @"Testing %@ ...", name);
+ struct Result result = [self _timeForSelector: testSels[i].sel];
+ struct Result overheadResult = [self _timeForSelector: @selector( testNothing )];
+
+ double total = result.totalDuration - overheadResult.totalDuration;
+ double each = result.singleIterationNanosec - overheadResult.singleIterationNanosec;
+
+ NSDictionary *entry = [NSDictionary dictionaryWithObjectsAndKeys:
+ name, @"name",
+ [NSNumber numberWithInt: result.iterations], @"iterations",
+ [NSNumber numberWithDouble: total], @"total",
+ [NSNumber numberWithDouble: each], @"each",
+ nil];
+ [resultsArray addObject: entry];
+
+ totalRunningTime += total;
+
+ NSNumber* eachN = [NSNumber numberWithDouble:each];
+ NSLog( @"completed %@ - Iter: %i, Time: %.1f s, Each: %@ ns", name, result.iterations, total, [nf stringFromNumber:eachN]);
+
+ // allow things to "cool down" before running the next test
+ mIterations = 1000000000;
+ [self _timeForSelector: @selector( testNothing )];
+ }
+
+ NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey: @"each" ascending: YES];
+ [resultsArray sortUsingDescriptors: [NSArray arrayWithObject: descriptor]];
+
+ //[str appendString: @"<p><table border=\"1\"><tr><td>Name</td><td>Iterations</td><td>Total Time (sec)</td><td>Per Exec Time (ns)</td></tr>"];
+ [str appendString: @"<p><table border=\"1\"><tr><td>Name</td><td>Each (ns)</td></tr>"];
+
+ NSEnumerator *enumerator = [resultsArray objectEnumerator];
+ id obj;
+ while( (obj = [enumerator nextObject]) )
+ {
+ NSString *name = [obj objectForKey: @"name"];
+ int iterations = [[obj objectForKey: @"iterations"] intValue];
+ double total = [[obj objectForKey: @"total"] doubleValue];
+ NSNumber* each = [NSNumber numberWithDouble:[[obj objectForKey: @"each"] doubleValue]];
+
+ //[str appendFormat: @"<tr><td>%@</td><td align=\"right\">%d</td><td align=\"right\">%.1f</td><td align=\"right\">%.1f</td></tr>", name, iterations, total, each];
+ [str appendFormat: @"<tr><td>%@</td><td align=\"right\">%@</td></tr>", name, [nf stringFromNumber:each]];
+ }
+ [str appendString: @"</table></p>\n"];
+
+ //[(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData: [str dataUsingEncoding: NSUTF8StringEncoding]];
+
+ NSString* logFileStr = [NSString stringWithContentsOfFile:logFile encoding:NSUTF8StringEncoding error:nil];
+ if (logFileStr == nil)
+ {
+#if TARGET_IPHONE_SIMULATOR
+ logFileStr = @"<font color=#ff0000><strong>IMPORTANT: THE RESULTS FROM THIS TEST RUN ARE COMPLETELY DEVOID OF ANY MEANING!<br/> \
+ The results below should not be compared, discussed, rated, evaluated, thought about or used in any other way or form!</strong></font><br><br> \
+ <a href=\"http://stackoverflow.com/questions/4825750/why-this-code-runs-slow-on-device-but-fast-on-simulator-in-iphone\">Why?</a><br/> \
+ Because you ran the tests on the <strong>iOS Simulator</strong>. That's like test-driving a Porsche through a cornfield. \
+ It's possible, but the results don't give any indication whatsoever to real-world, end-user performance.<br><br><strong> \
+ <font color=#ff0000>To get meaningful results you MUST run the tests on an iOS Device!</font></strong>";
+#else
+ logFileStr = @"A nanosecond (ns) is one billionth of a second (0.000 000 001 second). \
+ One nanosecond is to one second as one second is to 31.7 years. \
+ One Gigahertz (GHz) equals 1,000,000,000 Hz. One cycle of a 1 GHz CPU takes 1 nanosecond.";
+#endif
+ }
+ logFileStr = [NSString stringWithFormat:@"%@ %@", logFileStr, str];
+ [logFileStr writeToFile:logFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
+}
+
+- (void)beginTest
+{
+ mStartTime = mach_absolute_time();
+}
+
+- (void)endTestWithIterations: (int)iters
+{
+ mEndTime = mach_absolute_time();
+ mIterations = iters;
+}
+
+-(void) showResultsInView:(UIView*)view
+{
+ webView = [[UIWebView alloc] initWithFrame:[view frame]];
+ webView.exclusiveTouch = NO;
+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:logFile]]];
+ [view addSubview:webView];
+}
+
+-(void) printResultsToStandardOutput
+{
+ NSLog(@"Total Running Time: %.1f minutes", totalRunningTime / 60.0);
+ printf("\n\n\n");
+ NSString* logFileStr = [NSString stringWithContentsOfFile:logFile encoding:NSASCIIStringEncoding error:nil];
+ [(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:[logFileStr dataUsingEncoding:NSUTF8StringEncoding]];
+ printf("\n\n\n");
+}
+
+
+@end
View
135 Cocos2D-ARC-Performance-Test/Cocos2D-Performance-Test/PerfTester_ARCvsMRC.m
@@ -0,0 +1,135 @@
+//
+// PerfTester_ARCvsMRC.m
+// Cocos2D-ARC-Performance-Test
+//
+// Created by Steffen Itterheim on 20.03.13.
+//
+//
+
+#import "PerfTester.h"
+#import "ARCTests.h"
+#import "MRCTests.h"
+
+@implementation PerfTester (ARCvsMRC)
+
+#pragma mark algorithms
+
+-(void) testGeneticAlgorithmARC
+{
+ BEGIN ( 50 )
+ [arcTest runGeneticAlgorithm];
+ NSLog(@"%i out of %i complete", i, iters);
+ END()
+}
+-(void) testGeneticAlgorithmMRC
+{
+ BEGIN ( 50 )
+ [mrcTest runGeneticAlgorithm];
+ NSLog(@"%i out of %i complete", i, iters);
+ END()
+}
+
+-(void) testUnoptimizedContainsStringAlgorithmARC
+{
+ const char* string = "ein string, zwei string, drei string, vier string, fünf string, sechs string, sieben string, acht string\0";
+ NSData* data = [NSData dataWithBytes:string length:strlen(string)];
+
+ BEGIN ( k10KIterationTestCount )
+ [arcTest data:data containsCString:"sieben string"];
+ END()
+}