Skip to content

Commit

Permalink
fixup! InsertionSort for better performance on nearly-sorted data
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgriffin committed Jul 25, 2023
1 parent 7353830 commit 736349f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gflib/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void BuildOamBuffer(void)
sShouldProcessSpriteCopyRequests = TRUE;
}

static void InsertionSort(u32 *spritePriorities, u32 n)
static inline void InsertionSort(u32 *spritePriorities, u32 n)
{
u32 i = 1;
while (i < n)
Expand Down
22 changes: 11 additions & 11 deletions test/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,27 @@ TEST("BuildOamBuffer faster with max sprites (random y/subpriority)")
BenchmarkBuildOamBuffer(FALSE);
}

TEST("BuildOamBuffer faster with mix of sprites")
TEST("BuildOamBuffer faster on already-sorted max sprites")
{
u32 i;
ResetSpriteData_();
SeedRng(0);
for (i = 0; i < MAX_SPRITES / 2; i++)
{
u32 spriteId = CreateSprite(&gDummySpriteTemplate, 0, Random() % 160, Random() % 256);
gSprites[spriteId].invisible = Random() % 4 == 0;
}
BenchmarkBuildOamBuffer(FALSE);
for (i = 0; i < MAX_SPRITES; i++)
CreateSprite(&gDummySpriteTemplate, 0, Random() % 256, Random() % 256);
BenchmarkBuildOamBuffer(TRUE);
}

TEST("BuildOamBuffer faster on already-sorted max sprites")
TEST("BuildOamBuffer faster with mix of sprites")
{
u32 i;
ResetSpriteData_();
SeedRng(0);
for (i = 0; i < MAX_SPRITES; i++)
CreateSprite(&gDummySpriteTemplate, 0, Random() % 256, Random() % 256);
BenchmarkBuildOamBuffer(TRUE);
for (i = 0; i < MAX_SPRITES / 2; i++)
{
u32 spriteId = CreateSprite(&gDummySpriteTemplate, 0, Random() % 256, Random() % 256);
gSprites[spriteId].invisible = Random() % 4 == 0;
}
BenchmarkBuildOamBuffer(FALSE);
}

// Old implementation.
Expand Down

0 comments on commit 736349f

Please sign in to comment.