Vector vs. array V2.

This is a discussion on Vector vs. array V2. within the C++ Programming forums, part of the General Programming Boards category; here are results on my home computer, VS2008 (of which the SECURE_CTL flag works) Code: x = -802947072 a: 5.756 ...

  1. #16
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    here are results on my home computer, VS2008 (of which the SECURE_CTL flag works)
    Code:
    x = -802947072
    a: 5.756
    x = -802947072
    v: 6.397
    x = -802947072
    d: 5.885

  2. #17
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Code:
    g++ -O2 -fomit-frame-pointer -funroll-loops
    Code:
    x = -802947072
    a: 10.9
    x = -802947072
    v: 11.27
    x = -802947072
    d: 11.24
    GCC 4.2.3, 64-bit Linux.

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    I tried it 9 times, 3 each with different orders. Exact code as in the original post except changing the order in main. Using VC++ 7.1 Release build. vector wins every time no matter what I try with main. High and low examples:
    Code:
    x = -802947072
    a: 11.406
    x = -802947072
    v: 10.157
    x = -802947072
    d: 10.359
    Code:
    x = -802947072
    d: 10.281
    x = -802947072
    v: 9.687
    x = -802947072
    a: 10.094
    I ran this main and got the results below:
    Code:
    	{
    		V v;
    		TIME_IT(func, v);
    	}
    	{
    		D d;
    		TIME_IT(func, d);
    	}
    	{
    		D d;
    		TIME_IT(func, d);
    	}
    	{
    		V v;
    		TIME_IT(func, v);
    	}
    	{
    		V v;
    		TIME_IT(func, v);
    	}
    	{
    		D d;
    		TIME_IT(func, d);
    	}
    Code:
    x = -802947072
    v: 10.015
    x = -802947072
    d: 10.328
    x = -802947072
    d: 10.234
    x = -802947072
    v: 9.907
    x = -802947072
    v: 10.156
    x = -802947072
    d: 10.234
    VC++ 8.0 with _SECURE_SCL defined to 0:
    Code:
    x = -802947072
    d: 9.718
    x = -802947072
    v: 9.656
    x = -802947072
    v: 9.688
    x = -802947072
    d: 9.5
    x = -802947072
    d: 9.578
    x = -802947072
    v: 9.735
    The moral: there's little to no difference in speed. Meanwhile, look how easy it is to write the class with vector, and how easy it is to write a class with incorrect copy semantics with new[]/delete[].

  4. #19
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    No idea why, but here are my results ( VS2008 )
    Release Build with full optimization.
    Code:
    x = ...
    a: 11.969
    x = ...
    v: 113.64
    x = ...
    d: 18.359
    I don't understand why the results are so nutty.

    Intel Centrino Duo 1.6ghz processor, I would think it would be much faster than that.

    edit: that is with #define _SECURE_SCL 0
    Last edited by Raigne; 11-25-2008 at 12:43 AM.

  5. #20
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Where'd you put the #define?

  6. #21
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    Quote Originally Posted by Raigne View Post
    I don't understand why the results are so nutty.
    Simple. It means you screwed up the test. Something like an extra zero on the upper bound of one of the loops would do it...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by iMalc View Post
    Simple. It means you screwed up the test. Something like an extra zero on the upper bound of one of the loops would do it...
    But it's the same loop that does the work for all variants of the classes (unless the code has been changed from what I posted, of course).

    I think the problem has to do with the range checking (but how it can be 10x slower is a bit surprising).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I tried adding #define _SECURE_SCL 0 before all my #include directives too and that got the vector time down by a huge amount, but it was still about 50% higher than the others.
    I wonder if there's a difference between VC++ retail vs VC++ express? I no longer have a professional version that I can test it with -- only the express version.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  9. #24
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    There shouldn't be.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #25
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,414
    My results was often that the dynamic array was faster, but sometimes also slower, so I guess the results vary. Usually, it's about 10% difference in speed anyway, so not so much overhead.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    Quote Originally Posted by cpjust View Post
    I tried adding #define _SECURE_SCL 0 before all my #include directives too and that got the vector time down by a huge amount, but it was still about 50% higher than the others.
    I wonder if there's a difference between VC++ retail vs VC++ express? I no longer have a professional version that I can test it with -- only the express version.
    i couldn't get it working in VS2005. it worked in VS2008, could just be a bug or something.

  12. #27
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by bling View Post
    i couldn't get it working in VS2005. it worked in VS2008, could just be a bug or something.
    Why didn't it work? Compile error or runtime error...?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  13. #28
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    For my 2005 tests I used an old project that I use for random testing. There might be some settings I've tweaked to get the output I got. You may have to turn off more microsoft extensions in the project properties.

  14. #29
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    Quote Originally Posted by cpjust View Post
    Why didn't it work? Compile error or runtime error...?
    the _SECURE_CTL flag got ignored, so the vector results sucked.

  15. #30
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,414
    Really? Did you try to step through with the debugger?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21