Posted: Sat Mar 26, 2005 3:01 pm Post subject: (No subject)
well, i am not looking for minimal optimizations. I am inclined to believe STL vector is slower since it is not optimized for any specific type and plus of the overhead it carries. At least from my experience of the other STL wrappers they are slow as hell (deque, queue, list, stack, etc)
But seeing how struct is not working out, i probably have no other choice.
Sponsor Sponsor
bugzpodder
Posted: Sat Mar 26, 2005 3:11 pm Post subject: (No subject)
i found some benchmarking results on the net. without compiler optimization flags, arrays are definitely >>>>> faster than std::vectors
with some optimzation flags, they are about the same
wtd
Posted: Sat Mar 26, 2005 3:24 pm Post subject: (No subject)
Arrays are also dangerous, and inconvenient. So much of what you've written the STL would give you for free.
bugzpodder
Posted: Sat Mar 26, 2005 3:25 pm Post subject: (No subject)
rizzix wrote:
Note that if you want to initialzise members of class using a previously defined consructor always use the second method:
code:
BigInteger(int val) : BigInteger() {arr[0]=val;}
the compiler (DJGPP) refuses to accept this code :S
'BigInteger' is not immediate base case of 'BigInteger'
bugzpodder
Posted: Sat Mar 26, 2005 3:27 pm Post subject: (No subject)
wtd wrote:
Arrays are also dangerous, and inconvenient. So much of what you've written the STL would give you for free.
correct, but if you see some of the hardcore programmers who construct complete C programs in asm by hand in order to gain performance, you'll see that what I am trying in nothing. meh I guess i'll stick to vectors.
wtd
Posted: Sat Mar 26, 2005 4:10 pm Post subject: (No subject)
bugzpodder wrote:
wtd wrote:
Arrays are also dangerous, and inconvenient. So much of what you've written the STL would give you for free.
correct, but if you see some of the hardcore programmers who construct complete C programs in asm by hand in order to gain performance, you'll see that what I am trying in nothing. meh I guess i'll stick to vectors.
Yes, they're using C. C doesn't provide them with these conveniences, so they're not losing anything by not using the STL.
code:
if (C == CPP) pigs_fly();
As for your earlier comment... you can only use member variable names and immediate base class names.
rizzix
Posted: Sat Mar 26, 2005 4:10 pm Post subject: (No subject)
bugzpodder wrote:
the compiler (DJGPP) refuses to accept this code :S
'BigInteger' is not immediate base case of 'BigInteger'
oh, well then in that case, i take it back, only use it (when it comes to constructors) for intializing the base class' members through the base class's constructors.
(strange though, i wonder what is the ansi standard, i thought what i mentioned was pretty much ansi c++, but i could definitely be wrong)
bugzpodder
Posted: Sat Mar 26, 2005 4:17 pm Post subject: (No subject)
everything works as expected using vectors... must be array's fault :S
Sponsor Sponsor
bugzpodder
Posted: Sat Mar 26, 2005 4:49 pm Post subject: (No subject)
seems vectors is still too slow
USACO Training Grader Results for [bugz_po1]
12 users online
BGR/2 BRA/2 CAN/2 ITA/1 LTU/1 POL/1 POR/1 RUS/1 USA/1
TASK: buylow
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1 OK [0.01 secs]
Test 2 OK [0.01 secs]
Test 3 OK [0.01 secs]
Test 4 OK [0 secs]
Test 5 OK [0.02 secs]
Test 6 OK [0.09 secs]
Test 7 OK [0.05 secs]
Test 8 OK [0.12 secs]
Test 9 OK [0.19 secs]
Execution error: Your program (`buylow') used more than the allotted
runtime of 1 seconds (it ended or was stopped at 1.04 seconds) when
presented with test case 10, shown below.
Submit a file:
Be sure to include "LANG: C++", "LANG: JAVA", or whatever is appropriate.
EXPERIMENTAL GRADER -- Report *any* problem or unexpected result to Rob Kolstad
bugzpodder
Posted: Sat Mar 26, 2005 5:10 pm Post subject: (No subject)
passed the last test by adding & to the first variable of my add function. btw wtd, I tried to delete the macro and it actually up-ed my runtime to 10ms more.
wtd
Posted: Sat Mar 26, 2005 5:13 pm Post subject: (No subject)
Perhaps the compiler you're using is simply bad. If you're using Windows, why not use a recent version of MinGW rather than DJGPP?
wtd
Posted: Sat Mar 26, 2005 5:15 pm Post subject: (No subject)
As for & making a difference, yes, it will. C++, by default, uses pass-by-value arguments. The entire value passed in will be copied. This consumes memory and CPU time. Adding & to the type specifies a reference, and no copy is made.
Additionally, specifying const references where possible may yield performance gains.
bugzpodder
Posted: Sun Mar 27, 2005 12:16 pm Post subject: (No subject)
meh, I am using the judge's compiler.
someone told me exactly whats happening regarding my very first post. Its probably what you guys wanted to say, but he made it clearer to me.
Quote:
in C++ it is imposible to call a constructor from another one. What actually happens here is that you construct a temprary BigInteger object, that is immidiatly destroyed afterwards.
For the second problem: Have you implemented a copy constructor, assignment operator and destructor? If you don't actually allocate a new array, the old array may be destroyed by the time you try to use it.
time to benchmark if structs are faster than vectors