Â
I realized about a week ago that the slow performance of Crescendo (the game I am creating) was due, not to the slow Windows graphics library I am prototyping in, but due to a portion of my code called a quad tree that is supposed to be making the game faster. (Oops!
)
Â
Read on to see the results of optimizing the quad tree to make it 10 times faster.
Â
The problem was my use of the Standard Template Library’s set data structure (used in the code as std::set). Each quad tree node used a set to store all the game objects residing in its area of the game field.
Â
This is all well and good, but sets are fast at finding a random object in the set or determining if it is not in the set. Sets are not good at copying all their objects into another set.
Â
It turns out that the quad tree node’s most common operation is copying all of its objects into another collection, as the main game code wants to know which objects are around a given object at any given time, so the set was a poor choice for a data structure.
Â
Therefore, I replaced the std::set with a std::vector. A vector is another STL data structure that allows random access into any object it contains but is not optimal for finding a particular object. Then I used the std::copy algorithm to copy all the elements of the vector into another one when it needed to cough up all its objects.
Â
I got a good speed improvement from using the vector (2 to 4 times faster), but it was still pretty slow, and I figured that I could make something even faster, so I made my own vector class that stored the objects in a single block of memory and then did an old-school memcpy to copy its objects. The result was a 10x speed up from the set code.
Â
Here are the numbers (in milliseconds (ms) per game iteration):
set speed: 1.6 ms
vector speed: 0.44 ms
my fast vector speed: 0.12 ms
Subscribe
My Book
Follow with Google
Why Believe?
Published Articles
His:- Faith and Reason in the Context of Conversion
- My "Fathers for Good" Articles
- What's Good About Protestantism?
Recent Comments
- Steve Martin on “You Didn’t Share the Gospel”
- PMG on “You Didn’t Share the Gospel”
- Justin B. on “You Didn’t Share the Gospel”
- shawna on “You Didn’t Share the Gospel”
- PMG on “You Didn’t Share the Gospel”
- Drina on “You Didn’t Share the Gospel”
- Drina on “You Didn’t Share the Gospel”
- Devin Rose on “You Didn’t Share the Gospel”
- Steve Martin on “You Didn’t Share the Gospel”
- Brent on “You Didn’t Share the Gospel”
Tags
abortion ACORN adoption adult stem cells apologetics Beekeeping Biden Blogs canon of Scripture Catholic Life CCHD chickens contraception conversion easter ecumenism embryonic stem cells family farming Fatherhood gardening healthy food marriage McCain motherhood Natural Law Obama Orthodoxy Palin Politics Pope Benedict priesthood pro-life Regnum Christi saints scholarliness silverlight social media sustainable farming sustainable living The Book tower defense Tradition Virgin Mary VirtuePages
Links
- Aggie Catholics
- Almost Not Catholic
- Articuli Fidei
- Called to Communion
- Catholic Conversion Stories
- Catholic Nick
- Catholicity
- Christopher's Apologies
- Dave Armstrong
- Devin Rose
- Doug Beaumont
- Elizabeth Esther
- Evangelizing Catechesis
- Feminine Genius
- Fishing in the Tiber
- Forgotten Altars
- Ignitum Today
- Leila's Blog
- Love Being Catholic
- My Hermeneutical Spiral
- New Advent
- New Christendom
- Our Ave Maria Success Story
- Outside the Asylum
- Pater Noster
- Rachel Held Evans
- Richard Evans
- Sacramentum Vitae
- Seeking the Lamp in a Dark Place
- Shameless Popery
- Speak the Truth in Love
- That Strangest of Wars
- The American Catholic
- The Catholic Land Movement
- The Catholic UNapologist
- The Illustrious Danielle Bean
- The Impractical Catholic
- The Practicing Catholic
- The Pulp.it
- The Roman Road
- The Thin Veil
- Theophilogue
- Why I Am Catholic
Categories
Archives
Login
