Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
hyperPad

hyperPad Forum

  1. Home
  2. Help and Support
  3. Is a dictionary or an array faster?

Is a dictionary or an array faster?

Scheduled Pinned Locked Moved Help and Support
3 Posts 2 Posters 532 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • iTap DevelopmentI Offline
    iTap DevelopmentI Offline
    iTap Development
    wrote on last edited by
    #1

    If I have position x and y and rotation and want to be setting objects to those values, would it faster to have them as keys in a dictionary, or as indexes in an array?

    D 1 Reply Last reply
    0
    • iTap DevelopmentI iTap Development

      If I have position x and y and rotation and want to be setting objects to those values, would it faster to have them as keys in a dictionary, or as indexes in an array?

      D Offline
      D Offline
      Deeeds
      wrote on last edited by Deeeds
      #2

      @iTap-Development when in doubt, use arrays.

      Arrays are faster for almost everything, by an order of magnitude. Particularly in Objective-C, which is how they'd be implemented.

      The process of looking up, via a key, is quite slow, when compared with index lookups of arrays.

      When it comes to iterating through one or the other, arrays are often much more than an order of magnitude faster due to their inherently streamlined memory usage.

      Then there's unpacking.

      When you store x, y and rotation in a dictionary at a key, you have to "unpack" that to use it, which takes even longer.

      So you're best off having an array for each:

      arrayX
      arrayY
      arrayRotation
      arrayObjectName

      and iterating through when you need.

      iTap DevelopmentI 1 Reply Last reply
      0
      • D Deeeds

        @iTap-Development when in doubt, use arrays.

        Arrays are faster for almost everything, by an order of magnitude. Particularly in Objective-C, which is how they'd be implemented.

        The process of looking up, via a key, is quite slow, when compared with index lookups of arrays.

        When it comes to iterating through one or the other, arrays are often much more than an order of magnitude faster due to their inherently streamlined memory usage.

        Then there's unpacking.

        When you store x, y and rotation in a dictionary at a key, you have to "unpack" that to use it, which takes even longer.

        So you're best off having an array for each:

        arrayX
        arrayY
        arrayRotation
        arrayObjectName

        and iterating through when you need.

        iTap DevelopmentI Offline
        iTap DevelopmentI Offline
        iTap Development
        wrote on last edited by
        #3

        @Deeeds thanks!

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Search