optimization

Php - optimizing multiple counter increments

On a very heavy traffic LAMP server I'm using a memory table to keep track of several data items as counters. It is implemented like this: $query = "INSERT INTO daily_info_mem SET di_num=1 ,di_type=9, di_date = current_date(), di_sid= $sid_int ,di_name='user_counter' ON DUPLICATE KEY UPDATE di_num=di_num+1"; The index sets unique di_t...

is it reasonable to program an algortihm without function calls ?

Hi there ... I am programming a an algorithm for a library and I didn't use function calls at all. The algorithm is about 100 lines and there is no duplicate code.or should I use inlining ? ...

using JSTL to build tables

I'm using this JSTL code to generate an HTML table. Every other row is given a different class so we can give the table stripes. I know we can do this easily with CSS3 but I have to support old browsers. Anyway this is the code I use - it seems very heavy - is there an easier way to do it? <c:set var="oddEven" value="true" /> <c:forEac...

Which is better: Bookmark/Key Lookup or Index Scan

I know that an index seek is better than an index scan, but which is preferable in SQL Server explain plans: Index seek or Key Lookup (Bookmark in SQL Server 2000)? Please tell me they didn't change the name again for SQL Server 2008... ...

compute results and mux or not

Using pseudo code here. Are there pros and cons to these styles: Say you have an alu that can do add, and, or and xor. Is it better to have code that computes the possible answers all the time then select the answer based on the opcode (in this case a one hot): alu_add = a + b; alu_and = a & b; alu_or = a | b; alu_xor = a ^ b; ... ...

error using restrict keyword

In the following example: void foo (double *ptr) { const double * restrict const restr_ptr=ptr; } I get this error: error: expected a ";" const double * restrict const restr_ptr=ptr; ^ I compile with -std=c99, using gcc 3.4 Any Ideas? ...

Why does 'HASH JOIN' or 'LOOP JOIN' improve this stored proc?

I have a basic query that goes from 6 seconds to 1 second just by changing one join from LEFT JOIN to LEFT HASH JOIN or 'LEFT LOOP JOIN'. Can anyone explain why this would cause such a large increase in performance and why SQL's optimizer isn't figuring it out on it's own? Here is roughly what the SQL looks like: SELECT a.[ID] FROM...

Efficient computation of the high order bits of a multiplication

Many CPUs have single assembly opcodes for returning the high order bits of a 32 bit integer multiplication. Normally multiplying two 32 bit integers produces a 64 bit result, but this is truncated to the low 32 bits if you store it in a 32 bit integer. For example, on PowerPC, the mulhw opcode returns the high 32 bits of the 64 bit res...

PHP - Function inside a Function. Good or bad?

I would like to know if it is a good thing to define a function inside another function in PHP. Isn't it better to define it before the function (and not inside) in terms of performances. ...

profile java code

I need to profile my JAVA SRC code for some particular problem I am currently working on. I've been using the trial version of a tool called JProfiler. I'd like to learn of some good community open-source tools, if available; other than that I am also looking forward to learn of some standard techniques that are widely adopted (or must ...

Why is linker optimization so poor?

Recently, a coworker pointed out to me that compiling everything into a single file created much more efficient code than compiling separate object files - even with link time optimization turned on. In addition, the total compile time for the project went down significantly. Given that one of the primary reasons for using C++ is code ...

calling uniq and sort in different orders in shell

is there a difference in the order of uniq and sort when calling them in a shell script? i’m talking here about time- and space-wise. grep 'somePattern' | uniq | sort vs. grep 'somePattern' | sort | uniq a quick test on a 140 k lines textfile showed a slight speed improvement (5.5 s vs 5.0 s) for the first method (get uniq values a...

Optimizing cartesian requests with affine costs

Hello, I have a cost optimization request that I don't know how if there is literature on. It is a bit hard to explain, so I apologize in advance for the length of the question. There is a server I am accessing that works this way: a request is made on records (r1, ...rn) and fields (f1, ...fp) you can only request the Cartesian prod...

How to optimize the layers of pointer indirection

I am trying to optimize this sort of things in a heavy computing application: say I have a double d[500][500][500][500]; and the following is quite costly at least from compiler perspective double d[x][y][j][k] I want to tell compiler is that it's contiguous memory, to facilitate computing the offset. In my example, I have s...

Industrial partitioning problem

We're talking about metal products factory. There is machine which cuts long iron bars to smaller parts which are later used for creating various products. For example, I have requirement to produce bars of following length and quantity: 2 pieces of 248mm, 5 of 1150mm, 6 of 2843mm, 3 of 3621mm. That is the partitioning output. O...

Language features: optimizing booleans to flags + bitmasks.

I'm writing a programming language, and when I came across this question, my immediate thought was that languages should optimize booleans into bit flags for the programmer. This would keep all the benefits of speed and efficient memory usage while removing the burden of maintenance and the possibilities for errors caused by the more co...

Is optimizing certain functions with Assembler in a C/C++ program really worth it?

In certain areas of development such as game development, real time systems, etc., it is important to have a fast and optimized program. On the other side, modern compilers do a lot of optimization already and optimizing in Assembly can be time consuming in a world where deadlines are a factor to take into consideration. Questions: I...

What indexes can be used to improve this query?

This query selects all the unique visitor sessions in a certain date range: select distinct(accessid) from accesslog where date > '2009-09-01' I have indexes on the following fields: accessid date some other fields Here's what explain looks like: mysql> explain select distinct(accessid) from accesslog where date > '2009-09-01'; ...

Are public fields ever OK?

Before you react from the gut, as I did initially, read the whole question please. I know they make you feel dirty, I know we've all been burned before and I know it's not "good style" but, are public fields ever ok? I'm working on a fairly large scale engineering application that creates and works with an in memory model of a structur...

Optimizing IIS 6.0 performance on Windows Server 2003 Operating System

. Hi, We have built an ASP.NET application (with C#.net language) and hosted on IIS 6.0 on Windows Server 2003 Operating System. Now we need to optimize the IIS performance so that the pages get served fast. Would you please let me know if you have any idea on this? If would be great if you could provide the relevant doc or web ...