I'm considering micro-optimization of a huge CSS stylesheet and have a couple questions related to that:
Is lowercase better than uppercase for reducing file size?
Is background-position:right (5 chars); smaller than background-position:0 100%; (6 chars incl whitespace)?
Is there anything else that might help reduce file size? (Besid...
a) for(int i = 100000; i > 0; i--) {}
b) for(int i = 1; i < 100001; i++) {}
The answer is there on this website (question 3). I just can't figure out why?
...
I am curious as to what happens in this situation:
int i = 0;
MessageBox.Show(i++.ToString ());
MessageBox.Show(i++.ToString ());
Array[i++] = Foo;
Assuming this is the only way i is used in the method,does the JIT strip out i and replace it with literal values?
...
Suppose a bit sequence of size M, and another bit sequence of size N, with M >> N. Both M and N can be saved inside integer arrays: If N has a length of 30 then an array with only one integer will be needed, but if N has a length of 300 then an array with 10 integers will be needed to store it.
What I am trying to do is to shift N insi...
If possible, how can I improve the following quick sort(performance wise).Any suggestions?
void main()
{
quick(a,0,n-1);
}
void quick(int a[],int lower,int upper)
{
int loc;
if(lower<upper)
{
loc=partition(a,lower,upper);
quick(a,lower,loc-1);
quick(a,loc+1,upper)...
Just curious, which is more efficient?
This:
String a = someString + "." + anotherString;
Or this:
String a = someString + '.' + anotherString;
...
Are there any drawbacks to this code, which appears to be a faster (and correct) version of java.lang.Math.round?
public static long round(double d) {
if (d > 0) {
return (long) (d + 0.5d);
} else {
return (long) (d - 0.5d);
}
}
It takes advantage of the fact that, in Java, truncating to long rounds in to ...
im iterating through the array and sorting it by values into days of the week.
in order to do it i'm using quite many if statements.
does it make any difference for the processing speed if i use many ifs versus elseif statements?
...
Most code I have ever read uses a int for standard error handling (return values from functions and such). But I am wondering if there is any benefit to be had from using a uint_8 will a compiler -- read: most C compilers on most architectures -- produce instructions using the immediate address mode -- i.e., embed the 1-byte integer into...
Return types are frequently checked for errors. But, the code that will continue to execute may be specified in different ways.
if(!ret)
{
doNoErrorCode();
}
exit(1);
or
if(ret)
{
exit(1);
}
doNoErrorCode();
One way heavyweight CPU's can speculate about the branches taken in near proximity/locality using simple statistics - I...
Is there an appreciable performance difference between having one SELECT foo, bar, FROM users query that returns 500 rows, and 500 SELECT foo, bar, FROM users WHERE id = x queries coming all at once?
In a PHP application I'm writing, I'm trying to choose between a writing clear, readable section of code that would produce about 500 SEL...
Should I aggressively release memory while reading a file, line by line?
An example:
while (<FILE>) {
my $line = $_;
<process line>
undef($line);
}
"Undefing" the $line variable is a good option for reducing memory consumption?
...
Hello All,
What is the fastest and easiest way to get the last item of an array whether be indexed array , associative array or multi-dimensional array?
...
Is there any advantage in doing bitwise operations on word boundaries? Any CPU or memory optimization in doing so?
Actual problem:
I am trying to create XOR of two structure. Lets say structure-1 and structure-2 both of same size 10000 bytes. I leave first few hundreds bytes as it is and then start XOR of 1 and 2.
Lets say I start with...
I just want to know what the difference between all the conditional statements in objective-c and which one is faster and lighter.
...
In pondering optimization of code, I was wondering which was more expensive in python:
if x:
d = 1
else:
d = 2
or
d = 2
if x:
d = 1
Any thoughts? I like the reduced line count in the second but wondered if reassignment was more costly than the condition switching.
...
Suppose I have a class like
class Empty{
Empty(int a){ cout << a; }
}
And then I invoke it using
int main(){
Empty(2);
return 0;
}
Will this cause any memory to be allocated on the stack for the creation of an "Empty" object? Obviously, the arguments need to be pushed onto the stack, but I don't want to incur any extra ...
I just asked a question related to how the compiler optimizes certain C++ code, and I was looking around SO for any questions about how to verify that the compiler has performed certain optimizations. I was trying to look at the assembly listing generated with g++ (g++ -c -g -O2 -Wa,-ahl=file.s file.c) to possibly see what is going on un...
I'm going to be writing a multi-threaded shared memory messaging system for ultra high-volume message delivery between processes. The messages will originate from the worker threads of a web-server. I'd like to exploit the CPU cache locality that cores on the same CPU share. So that when I wake up a worker thread on the receiving end of ...
I understand most of the micro-optimizations out there but are they really useful?
Exempli gratia: does doing ++i instead of i++, or while(1) or for(;;) really result in performance improvements (either in memory fingerprint or CPU cycles)?
So the question is, what micro-optimizations can be done in C? Are they really useful?
...