The compiler command lines are contained within a text file buried within the Arduino application image, it is necessary to burrow down through a few directory levels to find a text file called "platform.txt".
In a Windows environment you need to open the folder where the arduino.exe is and find the file in the folder path.
See step 6 of this Instructable if you are using the latest 1.6.x IDE, as the file path to platform.txt has changed!
If you are nervous about messing something up then make a copy of the file somewhere!
Open the platform.txt file in WordPad (Notepad will not work due to the way the file is structured). Turn off "Word wrap" so lines can be counted more easily.
Find this line, about 16 lines down from the top:
compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD
Change the -Os to -O2 as below:
compiler.c.flags=-c -g -O2 -w -ffunction-sections -fdata-sections -MMD
Next find a second line a little further down the file, about 23 lines from the top:
compiler.cpp.flags=-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
Again, change the -Os to -O2 as below:
compiler.cpp.flags=-c -g -O2 -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
In practice it is just a case of changing the "s" to a "2". Note that is a letter "O" not a zero in the command line.
Now save the file, don't worry about any format warning. Next time it will open in Notepad OK!
Changing the compiler options will have no effect if you do it while you have the Arduino IDE open, you must close all the Arduino windows and open up the IDE again to get the change to be recognised.
I found my sketch ran a tiny weeny bit (a few microseconds!) faster with the first line changed to -O1 but the difference was far too small to notice when the sketch is running.