optimization

Does the .NET JIT optimize nested try/catch statements?

Hello: I've been thinking about nested try/catch statements and started to think about under which conditions, if any, the JIT can perform an optimization or simplification of the compiled IL. To illustrate, consider the following functionally-equivalent representations of an exception handler. // Nested try/catch try { try { ...

Difference between using from list and left join.

I have two database tables with the following structure: actions: action_id int(11) primary key action_name varchar(255) action_module varchar(45) permissions: perm_id int(11) primary key perm_role int(11) perm_action int(11) perm_status int(11) Now I have to check whether there is an entry in the permission...

Optimize file open and read

I have a C++ application running on Windows that wakes up every 15 mins to open & read files present in a directory. The directory changes on every run. open is performed by *ifstream.open(file_name, std::ios::binary)* read is performed by streambuf ios::rdbuf()* Total number of files every 15 mins is around 50,000 The files are opene...

Performance testing scenarios required

What can be the various performance testing scenarios to be considered for a website with huge traffic? Is there any way to identify the elements of the code which are adversely affecting the site performance? Please provide something similar to checklist of generalised scenarios to be tested to ensure proper performance testing. ...

Cost of passing an optional parameter to a method rather than computing it

I have a memory block that is divided into a series of location that can be retrieved and returned by client code. The method that returns locations back looks like this: void ReturnLocation(void *address) { int location = AddressToLocation(address); // I need the location here // some code DoSmthA(location); } void DoSmth...

Speed up this code - PHP/SQL - Short Code but takes incredibly long at the moment

Right, this code goes through a rather large multidimensional array (has about 28,000 rows and 16 parts). Order of events: Check if the data exists in the database if it exists - Update it with the new data if it doesn't exist - Insert it Simple. But right now to go through this it has taken over 30min i think and Still going. $c...

Eliminating Ugly Switch Statement When Retrieving Resources

I am adding a splash screen to a .NET compact application and am wondering if there's an elegant way to access the correct bitmap (based on screen resolution) for the splash screen. e.g. My resource bitmap properties are named like this... Splash640480 Splash480640 Splash480480 Splash320240 Splash240320 Splash240240 ... etc I tr...

OpenGL quad rendering optimization

I'm drawing quads in openGL. My question is, is there any additional performance gain from this: // Method #1 glBegin(GL_QUADS); // Define vertices for 10 quads glEnd(); ... over doing this for each of the 10 quads: // Method #2 glBegin(GL_QUADS); // Define vertices for first quad glEnd(); glBegin(GL_QUADS); // Define vertices for...

i++ less efficient than ++i, how to show this?

I am trying to show by example that the prefix increment is more efficient than the postfix increment. In theory this makes sense: i++ needs to be able to return the unincremented original value and therefore store it, whereas ++i can return the incremented value without storing the previous value. But is there a good example to show t...

What's faster IN or OR?

In T-SQL what's faster? DELETE * FROM ... WHERE A IN (x,y,z) Or DELETE * FROM ... WHERE A = x OR A = y OR A = z In my case x, y and z are input parameters for the stored procedure. And I'm trying to get the performance of my DELETE and INSERT statements to the best of my abilities. ...

Detect if C++ binary is optimized

Is there a flag or other reliable method to detect if a compiled C++ binary was compiled with optimizations? I'm okay with compiler-specific solutions. Edit: This is for a build deployment system, which could accidentally deploy binaries that were not built properly. A water-tight solution is unlikely, but it will save some pain (an...

In PHP, is printf more efficient than variable interpolation?

I want to know if the below code: <?php printf ("%s", $some_variable); ?> is more efficient than: <?php echo "$some_variable"; ?> One common complaint of variable interpolation is that it is very slow. I want to know if there is a better alternative to variable interpolation that doesn't make one's code as messy as: <?php echo $fi...

Optimisation of division in gcc

Here's some code (full program follows later in the question): template <typename T> T fizzbuzz(T n) { T count(0); #if CONST const T div(3); #else T div(3); #endif for (T i(0); i <= n; ++i) { if (i % div == T(0)) count += i; } return count; } Now, if I call this template function wit...

Problem with gcc gcse optimizer on PowerPC

Hi there. I noticed with -O2 level optimization using gcc 4.1 built on IBM AIX (for use with 5.3 and 6.1) that a bunch of lwz rxxx,offsetyyy(r2) sequences are added to an inline sequence, before bctrl (calling a method or function) is done. After the register is loaded, it is never used again after the return from the method or function...

What caching headers prevent browsers from requesting last modified dates from the server?

Since I version all my css/js/images, they never "change". It might go from sprite.4.png to sprite.5.png, but sprite.4.png will never change. Anyway, it seems pointless for the browsers to be checking for modified versions and receiving 304 responses, so what do I need to put in .htaccess to prevent these last modified look ups? Right ...

Why differ(!=,<>) is faster than equal(=,==) ?

Hello, I've seen comments on SO saying "<> is faster than =" or "!= faster than ==" in an if() statement. I'd like to know why is that so. Could you show an example in asm? Thanks! :) EDIT: Source Here is what he did. function Check(var MemoryData:Array of byte;MemorySignature:Array of byte;Position:integer):boolean; var i:by...

Does Drupal parse hooks that aren't being used?

Does Drupal parse (and/or run) hooks that are unrelated to the content being loaded by the current user? For example, say I had a module foo installed and active with the following hooks: <?php // .. stuff ... function foo_menu() { $items = array(); $items['foo/show'] = array( 'title' => t('Foo!'), 'pa...

Does the order of cases matter in PHP switch statements?

In PHP switch statements, does placing more common cases near the top improve performance? For example, say the following function is called 1,000 times: <?php function foo_user ($op) { switch ($op) { case 'after_update': //Some Stuff case 'login': //Some other Stuff } } If in 990 of the 1,000 of the tim...

Why Are There Multiple GET Requests Shown in Firebug?

So I'm at the stage in web programming where I'm past the "Look, Ma, I can put data in a grid and it shows up on the page." I'm now at the, wow, this site is not as snappy as I want it to be. So, I enabled the "Net" tab in Firebug, closed my eyes, crossed my fingers, and went spelunking. The first thing I noticed is that all of my .as...

Async loading in C# - optimization / proper usage?

So I want to make sure all of my database / network operations are not happening on the UI thread of my application. To do this I normally use the BeginInvoke function to make the call and then Invoke to do the actual update. I am not sure if I am doing things correctly compared to the way it should be done. Could anyone please provid...