Skip to content

Latest commit

 

History

History
109 lines (60 loc) · 5.13 KB

CppArrayExample6.md

File metadata and controls

109 lines (60 loc) · 5.13 KB

 

 

 

 

 

 

STL

 

Array example 6 is an array example.

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • Qt Qt: version 5.4.1 (32 bit)
  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppArrayExample6/CppArrayExample6.pro

 


QMAKE_CXXFLAGS += -std=c++1y -Wall -Wextra QT += core QT += gui CONFIG   += console CONFIG   -= app_bundle TEMPLATE = app include(../../Libraries/Boost.pri) SOURCES += main.cpp

 

 

 

 

 

./CppArrayExample6/main.cpp

 


#include <boost/date_time/posix_time/ptime.hpp> #include <boost/date_time/microsec_time_clock.hpp> #include <iostream> const int sz = 100000; struct Individual {   Individual() : m_v{std::vector<int>(1000,0)}   {   }   void Add() noexcept { ++m_v[0]; } private:   std::vector<int> m_v; //Make copying heavy }; void f(Individual v[sz]) {   for (int i=0; i!=sz; ++i)   {     v[i].Add();   } } void g(Individual * const v) {   for (int i=0; i!=sz; ++i)   {     v[i].Add();   } } int main() {   Individual v[sz];   const boost::posix_time::ptime start{boost::date_time::microsec_clock<boost::posix_time::ptime>::local_time()};   f(v);   const boost::posix_time::ptime after_f(boost::date_time::microsec_clock<boost::posix_time::ptime>::local_time());   g(v);   const boost::posix_time::ptime after_g(boost::date_time::microsec_clock<boost::posix_time::ptime>::local_time());   const boost::posix_time::time_duration d_f = after_f - start;   const boost::posix_time::time_duration d_g = after_g - start;   std::cout << d_f.total_microseconds() << " " << d_g.total_microseconds() << '\n' ; }