optimization

When to use Fixed Point these days

For intense number-crunching i'm considering using fixed point instead of floating point. Of course it'll matter how many bytes the fixed point type is in size, on what CPU it'll be running on, if i can use (for Intel) the MMX or SSE or whatever new things come up... I'm wondering if these days when floating point runs faster than ever...

State of "memset" functionality in C++ with modern compilers

Context: A while ago, I stumbled upon this 2001 DDJ article by Alexandrescu: http://www.ddj.com/cpp/184403799 It's about comparing various ways to initialized a buffer to some value. Like what "memset" does for single-byte values. He compared various implementations (memcpy, explicit "for" loop, duff's device) and did not really find ...

Speeding Up Python

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together: Firstly: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization? Secondly: When writing a program from scratch in python, what are some good ways to greatly ...

How often do you worry about how many if cases will need to be processed?

If you have the following: $var = 3; // we'll say it's set to 3 for this example if ($var == 4) { // do something } else if ($var == 5) { // do something } else if ($var == 2) { // do something } else if ($var == 3) { // do something } else { // do something } If say 80% of the time $var is 3, do you worry about th...

Is it worthwhile to use a bit vector/array rather than a simple array of bools?

When I want an array of flags it has typically pained me to use an entire byte (or word) to store each one, as would be the result if I made an array of bools or some other numeric type that could be set to 0 or 1. But now I wonder whether using a structure that is more space-efficient is worth it given the (albeit hopefully very slight)...

How can I speed up my Perl program?

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together: Firstly: Given an established Perl project, what are some decent ways to speed it up beyond just plain in-code optimization? Secondly: When writing a program from scratch in Perl, what are some good ways to greatly impr...

Size of varchar columns

In sql server does it make a difference if I define a varchar column to be of length 32 or 128? ...

How to determine optimal thread stack size?

Actually, two sizes: initially committed and total reserved. Do you use static or dynamic analysis? Which tools? Which techniques? ...

When should you start optimising code?

How do you know when you should worry about optimising code? Are there any rules of thumb for this? ...

Speeding Up Java

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together: Firstly: Given an established Java project, what are some decent ways to speed it up beyond just plain in-code optimization? Secondly: When writing a program from scratch in Java, what are some good ways to greatly impr...

Does using global create any overhead?

Is it a problem if you use the global keyword on variables you don't end up using? Compare: function foo() { global $fu; global $bah; if (something()) { $fu->doSomething(); } else { $bah->doSomething(); } } function bar() { if (something()) { global $fu; $fu->doSomething(); } ...

Speeding Up C#

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together: Firstly: Given an established C# project, what are some decent ways to speed it up beyond just plain in-code optimization? Secondly: When writing a program from scratch in C#, what are some good ways to greatly improve ...

JavaScript style/optimization: String.indexOf() v. Regex.test()

I've recently come across this piece of JavaScript code: if (",>=,<=,<>,".indexOf("," + sCompOp + ",") != -1) I was intrigued, because to write this test I would have done: if (/(>=|<=|<>)/.test(sCompOp)) Is this just a stylistic difference, or does the author of the other code know something about optimization that I don't? Or per...

Will reassigning a variable in every iteration of a loop affect performance?

Consider the following two ways of writing a loop in Java to see if a list contains a given value: Style 1 boolean found = false; for(int i = 0; i < list.length && !found; i++) { if(list[i] == testVal) found = true; } Style 2 boolean found = false; for(int i = 0; i < list.length && !found; i++) { found = (list[i] == testV...

Optimizing Flex when multiple modules are used

I have a Flex application where load time is extremely important (consumer site). i want to be able to get something up on screen and then allow additional modules to be loaded as necessary. The issue I'm facing is that the sum total of all the modules is much larger than if i were to include all the components in a single .swf file. I...

Which is fastest? SELECT SQL_CALC_FOUND_ROWS FROM `table`, or SELECT COUNT(*)

When you limit the number of rows to be returned by a SQL query, usually used in paging, there are two methods to determine the total number of records: Method 1 Include the SQL_CALC_FOUND_ROWS option in the original SELECT, and then get the total number of rows by running SELECT FOUND_ROWS(): SELECT SQL\_CALC\_FOUND\_ROWS * FROM tabl...

How do I detect Mobile Safari server side using PHP?

Mobile Safari is a very capable browser, and it can handle my website as it is perfectly. However, there are a few elements on my page that could be optimized for browsing using this device; such as serving specific thumbnails that are smaller than the desktop counterparts to help fit more content into the screen. I would like to know h...

ResultSet: Retrieving column values by index versus retrieving by label

When using JDBC, I often come across constructs like ResultSet rs = ps.executeQuery(); while (rs.next()) { int id = rs.getInt(1); // Some other actions } I asked myself (and authors of code too) why not to use labels for retrieving column values: int id = rs.getInt("CUSTOMER_ID"); The best explanation I've heard is some...

InstallShield Basic MSI optimizations

My InstallShield 2009 basic MSI project installs pretty slowly. We have a 65MB .msi and a 110MB .cab. The project was upgraded from IS12, using which it took about half as long to install. Did the 2009 upgrade make some default modifications that I can reverse? Are there any general optimizations that can speed up basic MSI projects? ...

Seriously, should I write bad PHP code?

I'm doing some PHP work recently, and in all the code I've seen, people tend to use few methods. (They also tend to use few variables, but that's another issue.) I was wondering why this is, and I found this note "A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. ...