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 6477563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:57:48+00:00 2026-05-25T06:57:48+00:00

So I try to create simple speed bench with boost 1.47.0. But results like

  • 0

So I try to create simple speed bench with boost 1.47.0. But results like 1.423 are not detailed enough for me. I need more detailed ones. How to get tham? How to make boost::timer show microseconds?

bench code:

#include <iostream>
#include <boost/thread.hpp>
#include <map>
#include <boost/thread.hpp>
#include <boost/thread/locks.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random.hpp>
#include <boost/timer.hpp>
#include <boost/progress.hpp>

class TestDs 
{
public:

    virtual bool containsKey(int key)=0;
    virtual int get(int key)=0;
    virtual int put(int key, int value)=0;
    virtual int remove(int key)=0;

    virtual int size()=0;
    virtual const char* name()=0;
    virtual void print()=0;
    virtual void shutdown()=0;
};

class GeneralMap: public TestDs
{
private:

    std::map<int,int> _ds;
    mutable boost::mutex mut_;
public:
    GeneralMap() {}

    bool containsKey(int key) {
        boost::mutex::scoped_lock lock(mut_);
        if ( _ds.find(key) != _ds.end())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    int get(int key) {
        boost::mutex::scoped_lock lock(mut_);
        return _ds[key];
    }

    int put(int key, int value) {
        boost::mutex::scoped_lock lock(mut_);
        _ds.insert(std::pair<int, int>(key,value));
        return key;
    }

    int remove(int key) {
        boost::mutex::scoped_lock lock(mut_);
        return _ds.erase(key);
    }

    int size() {
        boost::mutex::scoped_lock lock(mut_);
        return _ds.size();
    }
    const char* name() {
        return "StdMap";
    }
    void print() {}
    void shutdown() {}

};


int n;
boost::shared_mutex  tests;
boost::shared_mutex  results;
boost::random::mt19937 rng;
boost::timer timerForCaptureFame;
GeneralMap Ds;
boost::progress_display *show_progress;

void test( int i)
{
    boost::shared_lock<boost::shared_mutex> lock_r(results);
    boost::shared_lock<boost::shared_mutex> lock(tests);
    Ds.put(i, 0);
    if (Ds.containsKey(i))
    {
        Ds.get(i);
    }
    Ds.remove(i);
    ++(*show_progress);

}

void result()
{
    boost::upgrade_lock<boost::shared_mutex> lock(results);
    boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);

    std::cout <<  std::endl << "test of " << Ds.name() << " complite;" << std::endl << "test performed on " << n << " items" << std::endl << "test duration: " << timerForCaptureFame.elapsed() << std::endl;
}

void create_tests( int n)
{

    boost::upgrade_lock<boost::shared_mutex> lock(tests);
    boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);

    boost::shared_lock<boost::shared_mutex> lock_r(results);

    for(int i=0; i<n; i++)
    {
        boost::random::uniform_int_distribution<> ran = boost::random::uniform_int_distribution<>(1, n*10);
        int x = ran(rng);
        boost::thread worker(test, x);
    }
    boost::thread worker_r(result);
    timerForCaptureFame.restart();
    return;
}



int main()
{
    n = 1000;
    show_progress = new boost::progress_display(n);
    create_tests(n);
    std::cin.get();
    return 0;
}
  • 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. Editorial Team
    Editorial Team
    2026-05-25T06:57:50+00:00Added an answer on May 25, 2026 at 6:57 am

    See if this thread from the Boost mailing page helps.
    And you could look at this Stackoverflow question

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

Sidebar

Related Questions

Hy, i'm try to create a simple Telnet Server in python, but the server
I try to create simple example for AdMob but I failed. This is my
I try to create a very simple app using windows API. I've done some
I want to try create something like Zend's Server Pagecache. What I want to
I want to create simple equalizer for android. How can I do it? Try
I try to create simple web service with CXF, Jetty and Spring. I create
How can I create a simple maven project using m2e ? I just need
i'm a newbie in.net and im try to create a simple site. I have
Having XNA background, I try to create a simple DirectX11 application. Now I try
I try to create a very simple physics engine for my study (processing used

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.