Don't confuse fewer lines of C code with fast. Worst case (the array isn't in cache) this will be much slower than a loop or some of the other tricks mentioned above.
Type: Posts; User: KCfromNC
Don't confuse fewer lines of C code with fast. Worst case (the array isn't in cache) this will be much slower than a loop or some of the other tricks mentioned above.
If there's no restrictions in the homework, you could do this using memmove().
Pretty close, but more likely here is that GCC is able to optimize some calls to math lib functions away completely when you pass in constants. Not sure why the second case can't be optimized away...
Yep. Probably easiest if the for loop runs from 'a' to 'z', inclusive, and either keep a separate counter for the number of letters printed so far or realize that value is the current letter minus...
Not minimizing the work you guys have done to figure this out, but notice that the professor's "optimization" requirements have changed what could have been simple straight-line floating point code...
Modern versions of GCC have -Ofast as an option. You could try this as an alternative to -O3 and see if it does anything different.
Wouldn't the most efficient implementation use something like scalbn() or ldexp()? It isn't the answer the HW is looking for, but it isn't the student's fault if the teacher asks the wrong question...
Another way to do this :
# Use variables for the target ($@ = demo here) and the dependencies ($^ = main.o f1.o f2.o)
demo : main.o f1.o f2.o
gcc -o $@ $^
# Define a generic...
On certain x86 hardware and OS combinations, maybe. Even on systems using x87 code, it could still depend on whether the code is FPU bound or memory bound. And even taking that into account, using...
You're getting a pointer, not an array. This is a perfectly valid function call :
unsigned char foo = 0xAB;
shift(&foo, sizeof(foo));
Or a variable can end up being more than 2 bytes :
...
make each entry of your stack a void * and a variable identifying the type. Create push_char_array and push_int functions - each mallocs space for the appropriate var, copies it into this space,...
llvm-gcc is a front end for LLVM based on gcc 4.2.x (where I can't remember the x). That puts it as older than the 4.3 needed to have the __COUNTER__ macro added to gcc. Clang is a gcc-alike front...
Link the application against a static version of the library. The details of how to do this vary by compiler and OS, so we'll need more information to help you.
Or it will be 12 bytes or 16 bytes or maybe 4 bytes, or something totally different. It very rarely matters - and usually then it only matters when you're doing something you shouldn't. When it...
Replace 4 * 2 * level / 10 with 4 + 2 * level/10.
The bigger question is whether or not the original code is more correct that either of the simplifications listed in the thread.
But another approach is a to have a lookup table of base values...
The compiler isn't guaranteed to allocate memory for them in the first place - they could be stored in registers, replaced by a constant in an opcode, or removed entirely if they are dead code - so...
Which is balanced by the number of tasks you eliminate by looping up to the sqrt rather than up to n/2. It's not like mod of an arbitrary integer is a cost-free operation in itself, so if you...
Only if you're talking about code size. If you're interested in speed, the only real way to know is to run and time each example.
Yes, that's why you should be testing using a loop. First test 3 as a factor and add 2 each time through the loop. Exit the loop when you've passed the sqrt of p. That way if p is large enough...
How many cereal box tops do I need to send in to get this?
I studied main carefully, as the directions say. This should pass all the test cases provided.
/* The spec says that the result of this function is never used, so it's a NOP */
void...
All versions? How far back do you want to go? Windows 1.0? Windows 95?
I'm not sure how one loop is going to run faster than the other when any reasonable compiler is going to remove those loops as dead code anyway. I wonder if he was trying to test how fast the code...
You'll need to ask the right question - do you want to run on all machines or just on all Windows machines? Those are two very different goals.