premature-optimization

When is optimisation premature?

As Knuth said, We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. This is something which often comes up in Stack Overflow answers to questions like "which is the most efficient loop mechanism", "SQL optimisation techniques?" (and so on). The standard answer to thes...

Creating Local variables in .Net

Hey all, I just want to know that creating local variables to accept the return value of function is going to hit memory usage or performance in .Net applications , especially in ASP.Net. say MyObject myObject = Foo(); MyOtherObject myOtherObject = Boo(); SomeFuntion(myObject, myOtherObject); OR Should I use MyFunction(Foo(),...

Does rearranging a conditional evaluation speed up a loop?

Bit of a weird one: I was told a while ago by a friend that rearranging this example for loop from : for(int i = 0; i < constant; ++i) { // code... } to: for(int i = 0; constant > i; ++i) { // code... } would slightly increase performance in C++. I don't see how comparing a constant value to a variable is faster than vice-...

Which piece of code is more performant?

Hi folks, I have some code i'm revewing, which is used to convert some text into an MD5 Hash. Works great. It's used to create an MD5Hhash for a gravatar avatar. Here it is :- static MD5CryptoServiceProvider md5CryptoServiceProvider = null; public static string ToMD5Hash(this string value) { //creating only when needed if (md5...

Java foreach efficiency

I have something like this: Map<String, String> myMap = ...; for(String key : myMap.keySet()) { System.out.println(key); System.out.println(myMap.get(key)); } So is myMap.keySet() called once in the foreach loop? I think it is, but want your opinion. I would like to know if using foreach in this way (myMap.keySet()) has a pe...

In terms of today's technology, are these meaningful concerns about data size?

We're adding extra login information to an existing database record on the order of 3.85KB per login. There are two concerns about this: 1) Is this too much on-the-wire data added per login? 2) Is this too much extra data we're storing in the database per login? Given todays technology, are these valid concerns? Background: We don'...

passing a string by reference to a function would speed things up? (php)

Possible Duplicate: In PHP (>= 5.0), is passing by reference faster? I wonder if by declaring the parameter pass by reference, the PHP interpreter will be faster for not having to copy the string to the function's local scope? The script turns XML files into CSVs, which have thousands of records, so little time optimizations cou...

What is the Cost of Calling array.length

While updating for loops to for-each loops in our application, I came across a lot of these "patterns": for (int i = 0, n = a.length; i < n; i++) { ... } instead of for (int i = 0; i < a.length; i++) { ... } I can see that you gain performance for collections because you don't need to call the size() method with each loop. ...

Any good literature on join performance vs systematic denormalization ?

As a corollary to this question I was wondering if there was good comparative studies I could consult and pass along about the advantages of using the RDMBS do the join optimization vs systematically denormalizing in order to always access a single table at a time. Specifically I want information about : Performance or normalisation v...

At which n does binary search become faster than linear search on a modern CPU?

Due to the wonders of branch prediction, a binary search can be slower than a linear search through an array of integers. On a typical desktop processor, how big does that array have to get before it would be better to use a binary search? Assume the structure will be used for many lookups. ...

Is it premature optimization to develop on slow machines?

We should develop on slow boxen because it forces us to optimize early. Randall Hyde points out in The Fallacy of Premature Optimization, there are plenty of misconceptions around the Hoare quote: We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. In particular...

Python | efficiency and performance

Lets say I'm going to save 100 floating point numbers in a list by running a single script, most probably it will take some memory to process.So if this code executes every time as a requirement of an application there will be performance hits, so my question is how to maintain efficiency in order to gain performance. Mock-up code: def...

Which is better Java programming practice for looping up to an int value: a converted for-each loop or a traditional for loop?

Hi folks, Given the need to loop up to an arbitrary int value, is it better programming practice to convert the value into an array and for-each the array, or just use a traditional for loop? FYI, I am calculating the number of 5 and 6 results ("hits") in multiple throws of 6-sided dice. My arbitrary int value is the dicePool which re...

Is count(*) really expensive ?

I have a page where I have 4 tabs displaying 4 different reports based off different tables. I obtain the row count of each table using a select count(*) from <table> query and display number of rows available in each table on the tabs. As a result, each page postback causes 5 count(*) queries to be executed (4 to get counts and 1 for ...

Calling a getter multiple times or calling once and assigning to a variable?

say suppose I have class as : public class Age { private int age; public int getAge() { return this.age; } } In my Main class I am calling the getAge() method many times. So I wanted to know is it advisable to call so many times or call once and assign it to some variable and use that variable. Which is best a...

Can knowing C actually hurt the code you write in higher level languages?

The question seems settled, beaten to death even. Smart people have said smart things on the subject. To be a really good programmer, you need to know C. Or do you? I was enlightened twice this week. The first one made me realize that my assumptions don't go further than my knowledge behind them, and given the complexity of software ru...

Should i use HttpResponse.End() for a fast webapp?

HttpResponse.End() seems to throw an exception according to msdn. Right now i have the choice of returning a value to say end thread (it only goes 2 functions deep) or i can call end(). I know that throwing exceptions is significantly slower (read the comment for a C#/.NET test) so if i want a fast webapp should i consider not calling i...

Am I understanding premature optimization correctly?

I've been struggling with an application I'm writing and I think I'm beginning to see that my problem is premature optimization. The perfectionist side of me wants to make everything optimal and perfect the first time through, but I'm finding this is complicating the design quite a bit. Instead of writing small, testable functions that d...

Computation overhead in C# - Using getters/setters vs. modifying arrays directly and casting speeds

I was going to write a long-winded post, but I'll boil it down here: I'm trying to emulate the graphical old-school style of the NES via XNA. However, my FPS is SLOW, trying to modify 65K pixels per frame. If I just loop through all 65K pixels and set them to some arbitrary color, I get 64FPS. The code I made to look-up what colors s...

Java bytecode compiler benchmarks

Q.1. What free compiler produces the most optimal Java bytecode? Q.2. What free virtual machine executes Java bytecode the fastest (on 64-bit multi-core CPUs)? Q.3. What other (currently active) compiler projects are missing from this list: http://www.ibm.com/developerworks/java/jdk/ http://gcc.gnu.org/java/ http://openjdk.java.net/g...