Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 110597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:15:07+00:00 2026-05-11T02:15:07+00:00

I am trying to compare the performance of boost::multi_array to native dynamically allocated arrays,

  • 0

I am trying to compare the performance of boost::multi_array to native dynamically allocated arrays, with the following test program:

#include <windows.h> #define _SCL_SECURE_NO_WARNINGS #define BOOST_DISABLE_ASSERTS  #include <boost/multi_array.hpp>  int main(int argc, char* argv[]) {     const int X_SIZE = 200;     const int Y_SIZE = 200;     const int ITERATIONS = 500;     unsigned int startTime = 0;     unsigned int endTime = 0;      // Create the boost array     typedef boost::multi_array<double, 2> ImageArrayType;     ImageArrayType boostMatrix(boost::extents[X_SIZE][Y_SIZE]);      // Create the native array     double *nativeMatrix = new double [X_SIZE * Y_SIZE];      //------------------Measure boost----------------------------------------------     startTime = ::GetTickCount();     for (int i = 0; i < ITERATIONS; ++i)     {         for (int y = 0; y < Y_SIZE; ++y)         {             for (int x = 0; x < X_SIZE; ++x)             {                 boostMatrix[x][y] = 2.345;             }         }     }     endTime = ::GetTickCount();     printf('[Boost] Elapsed time: %6.3f seconds\n', (endTime - startTime) / 1000.0);      //------------------Measure native-----------------------------------------------     startTime = ::GetTickCount();     for (int i = 0; i < ITERATIONS; ++i)     {         for (int y = 0; y < Y_SIZE; ++y)         {             for (int x = 0; x < X_SIZE; ++x)             {                 nativeMatrix[x + (y * X_SIZE)] = 2.345;             }         }     }     endTime = ::GetTickCount();     printf('[Native]Elapsed time: %6.3f seconds\n', (endTime - startTime) / 1000.0);      return 0; } 

I get the following results:

[Boost] Elapsed time: 12.500 seconds [Native]Elapsed time:  0.062 seconds 

I can’t believe multi_arrays are that much slower. Can anyone spot what I am doing wrong?

I assume caching is not an issue since I am doing writes to memory.

EDIT: This was a debug build. Per Laserallan’s suggest I did a release build:

[Boost] Elapsed time:  0.266 seconds [Native]Elapsed time:  0.016 seconds 

Much closer. But 16 to 1 still seems to high to me.

Well, no definitive answer, but I’m going to move on and leave my real code with native arrays for now.

Accepting Laserallan’s answer because it was the biggest flaw in my test.

Thanks to all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:15:07+00:00Added an answer on May 11, 2026 at 2:15 am

    Are you building release or debug?

    If running in debug mode, the boost array might be really slow because their template magic isn’t inlined properly giving lots of overhead in function calls. I’m not sure how multi array is implemented though so this might be totally off 🙂

    Perhaps there is some difference in storage order as well so you might be having your image stored column by column and writing it row by row. This would give poor cache behavior and may slow down things.

    Try switching the order of the X and Y loop and see if you gain anything. There is some info on the storage ordering here: http://www.boost.org/doc/libs/1_37_0/libs/multi_array/doc/user.html

    EDIT: Since you seem to be using the two dimensional array for image processing you might be interested in checking out boosts image processing library gil.

    It might have arrays with less overhead that works perfectly for your situation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Huh? Do you have Visual C# component installed? You should… May 12, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer I've done this recently. I needed to query FlexLM license… May 12, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer It sounds like you're looking for the Windows Communication Foundation… May 12, 2026 at 12:32 am

Related Questions

I am trying to compare the performance of several Javascript libraries. Although measuring transaction
I'm investigating the differences between using log4net and System.Diagnostics.Trace for logging, and I'm curious
I am looking at the pricing of various cloud computing platforms, particularly Amazon's EC2,
I recently read the excellent article The Transactional Memory / Garbage Collection Analogy by

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.