optimization

How do I optimize this export feature for LAMP web app?

Hi guys & ladies, I have a feature which allows the user to create projects and view it on this page. They could import resources(pdf,img,etc) to be kept along with their projects. So now i want to create a feature which allows the user to export all their stuff and those people who are in the same group as them all neatly with pretty r...

Caching database data in Session - getting the balance right

If you cache data from your database in ASP.NET Session then you will speed up subsequent requests for that data (note: depending on the serialization/deserialization cost of the data concerned), at the expense of memory load in IIS. (OK, this is probably a simplification of the reality of the situaiton - feel free to correct or refine ...

Optimising if statements by reordering

I remember reading once that the order of the members of an evaluation is important. Such as if (null == myClass) is better (faster?) then if (myClass == null) is this the case? If so could someone explain how and why? If the answer requires a language then aim towards c#. Thanks ...

PosgreSQL Query Optimization and the Postmaster Process'

Hi again, I currently working with a larger wikipedia-dump derived PostgreSQL database; it contains about 40 GB of data. The database is running on an HP Proliant ML370 G5 server with Suse Linux Enterprise Server 10; I am querying it from my laptop over a private network managed by a simple D-Link router. I assigned static DHCP (private...

using static Regex.IsMatch vs creating an instance of Regex

In C# should you have code like: public static string importantRegex = "magic!"; public void F1(){ //code if(Regex.IsMatch(importantRegex)){ //codez in here. } //more code } public void main(){ F1(); /* some stuff happens...... */ F1(); } or should you persist an instance of a Regex containing the important pattern?...

Why does the SqlServer optimizer get so confused with parameters?

I know this has something to do with parameter sniffing, but I'm just perplexed at how something like the following example is even possible with a piece of technology that does so many complex things well. Many of us have run into stored procedures that intermittently run several of orders of magnitude slower than usual, and then if yo...

Adding values in various combinations

Not sure how best to explain it, other than using an example... Imagine having a client with 10 outstanding invoices, and one day they provide you with a cheque, but do not tell you which invoices it's for. What would be the best way to return all the possible combination of values which can produce the required total? My current th...

Most efficient way to find elements in jQuery

If I have a CSS class which I only ever apply to form elements, eg: <form class="myForm"> Which of these two jQuery selectors is most efficient, and why? a) $('form.myForm') b) $('.myForm') ...

Optimizing PHP string concatenation

Hello there, This post is not really a question, but it could be useful to share some coding tips. Here is the one I'de like to share with you. I'm gonna show you 4 examples to do the same thing, but only the last one will be the best. $foo = 'John SMITH'; echo "Hello $foo, welcome on my website."; echo "Hello " . $foo . " welcome o...

Minimizing the sum of a special function over a list

Say I have a list and I want it arranged so that the sum of a certain function operating over its consecutive elements is minimum. For example consider the list { 1, 2, 3, 4 } and sum a^b for consecutive pairs (a,b) over the entire list. ie. 1^2 + 2^3 + 3^4 = 90. By inspection, the minimum sum is achieved when the list is arranged as {...

getting 'System.OutOfMemoryException' when converting byte array to string

code snippet: //byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[]) ((dbCommand.Parameters["parameter"].Value)); string myString =System.Text.Encoding.UTF8.GetString(myByteArray); Xmldocument doc = new Xmldocument(); doc.Load(myString); ============ I am getting System.OutOfMemoryException sometime...

What is the fastest way(s) to loop through a large data chunk on a per-bit basis.

I am running through a memory block of binary data byte-wise. Currently I am doing something like this: for (i = 0; i < data->Count; i++) { byte = &data->Data[i]; ((*byte & Masks[0]) == Masks[0]) ? Stats.FreqOf1++; // syntax incorrect but you get the point. ((*byte & Masks[1]) == Masks[1]) ? Stats.FreqOf1++; ((*byte ...

Will Oracle optimizer use multiple Hints in the same SELECT?

I'm trying to optimize query performance and have had to resort to using optimizer hints. But I've never learned if the optimizer will use more than one hint at a time. e.g. SELECT /*+ INDEX(i dcf_vol_prospect_ids_idx)*/ /*+ LEADING(i vol) */ /*+ ALL_ROWS */ i.id_number, ... FROM i_table i JOIN vol_ta...

Find minimal path in a tree with multivalued nodes

Hi My math classes are far behind, and I'm currently struggling to find a decent solution to a problem I'm having: I have a tree, in which nodes are actions, and are "weighted" according to multiple criteria : the cost of said action, the time it will take, the necessary resources, the disturbance, etc... And I want to to find in this ...

How to get better performances using TIBCO RV from C#?

I'm using TIBCO RV .NET API (TIBCO.Rendezvous.dll). Do you know if there is a better way, in term of performance, to receive and read messages from a RV channel in C#? I found the Message type - the logical wrapper over a RV message - being quite heavy. Getting a field by name or by index could be pretty slow, especially when we consid...

Javascript Fibonacci nth Term Optimization

I've become interested in algorithms lately, and the fibonacci sequence grabbed my attention due to its simplicity. I've managed to put something together in javascript that calculates the nth term in the fibonacci sequence in less than 15 milliseconds after reading lots of information on the web. It goes up to 1476...1477 is infinity a...

Generate webpages directly from database or cache?

[I'm not asking about the architecture of SO, but it would be helpful to the question.] On SO, when a user clicks on his/her name and clicks on "responses" they see other users responses to comment threads, questions, and answers in which they have participated. I've had the sneaking suspicion that I've missed certain responses out ther...

How to speed up floating-point to integer number conversion?

We're doing a great deal of floating-point to integer number conversions in our project. Basically, something like this for(int i = 0; i < HUGE_NUMBER; i++) int_array[i] = float_array[i]; The default C function which performs the conversion turns out to be quite time consuming. Is there any work around (maybe a hand tuned functi...

How can I make this query easier to write

I have a query that pulls up questions from one table and answers from another. SELECT questions.question, questions.answers, (SELECT COUNT(answer) FROM answers WHERE question_id = 1 AND answer = 1 GROUP BY answer) as ans1, (SELECT COUNT(answer) FROM answers WHERE question_id = 1 AND answer = 2 GROUP BY...

How to deal with compiler optimization problems

I'm having an annoying problem with my iPhone app. Whenever I set the optimization level to something other than "None", I get computation errors. This only happens in when building for the iPhone SDK (the iPhone Simulator is always fine). I wouldn't mind disabling optimizations in release mode, but the application is a tiny bit too s...