optimization

Sorting x and y coordinates in an array in PHP most efficently?

Currently I have an array that contains x and y coordinates of various positions. ex. $location[0]['x'] = 1; $location[0]['y'] = 1 This indicates id 0 has a position of (1,1). Sometimes I want to sort this array by x, and other times by y. Currently I am using array-multisort() to sort my data, but I feel this method is inefficient s...

What are some hints that an algorithm should parallelized?

My experience thus far has shown me that even with multi-core processors, parallelizing an algorithm won't always speed it up noticably. In fact, sometimes it can slow things down. What are some good hints that an algorithm can be sped up significantly by being parallelized? (Of course given the caveats with premature optimization...

What profiling tools are available for C#.NET?

Edit: Duplicate of http://stackoverflow.com/questions/3927/what-are-some-good-net-profilers In a previous life as a C++ developer on Linux, I found the built-in profiler gprof to be very handy for finding the best targets for optimization. Is there a similar tool available for C# or the .NET CLR in general? What profiling tool options...

Fastest method for checking overflow?

Here's my attempt. Any tips on a better solution?: // for loop to convert 32 to 16 bits uint32_t i; int32_t * samps32 = (int32_t *)&(inIQbuffer[0]); int16_t * samps16 = (int16_t *)&(outIQbuffer[0]); for( i = 0; i < ( num_samples * 2/* because each sample is two int32 s*/ ); i++ ) { overflowCount += ( abs(samps32[i]) & 0xFFFF8000 ) ?...

Can I Flush the Buffer Early Using ASP.NET?

Best Practices for Speeing Up Your Web Site from Yahoo includes the following recommendation: When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It all...

How to implement autocomplete on a massive dataset

I'm trying to implement something like Google suggest on a web site I am building and am curious how to go about doing in on a very large data set. Sure if you've got 1000 items you cache the items and just loop through them. But how do you go about it when you have a million items? Further, suppose that the items are not one word. Speci...

Fastest way to create a list of unique strings from within a loop?

I have a set of strings (~80 000) I can only access sequentially by the hits.Doc(int).Get("fieldName") method. List<string> idStrings = new List<string>(); int count = hits.Length(); for (int i = 0; i < count; i++) { string idString = hits.Doc(i).Get("id"); if (!idStrings.Contains(idString)) idStrings.Add(idString); } ...

Declaring structures within functions in C

I have a structure that only one function must access. The function converts tokens like "k, K, kb, KB, m, M, mb, MB, ..." into an actual unit. The purpose of this is to simplify a configuration file. So, suppose we have: static uint32_t real_unit(const char *str) { struct u2type { char key[3]; uint32_t val; } const...

OnLive: How does it work?

OnLive is a cloud computing solution for gaming. It offers streaming of high-end games to any pc, regardless of its hardware. I wonder how it works: sending raw HD res image and audio data seems unlikely. Would relatively simple compression, like jpeg and mp3/ogg, do the trick? ...

Improving performance Linq to Sql Compact Edition

Hi I'm writing a WPF client app, using Linq to Sql with Sql Compact edition. The db is relatively small (3MB) and read-only. Bottom line is that The performance are not as good as I hoped them to be, and I'm looking for tips and practical ways to increase that. More facts: The schema contains around a dozen of entities with extensive r...

User defined function replacing WHERE col IN(...)

I have created a user defined function to gain performance with queries containing 'WHERE col IN (...)' like this case: SELECT myCol1, myCol2 FROM myTable WHERE myCol3 IN (100, 200, 300, ..., 4900, 5000); The queries are generated from an web application and are in some cases much more complex. The function definition looks like this:...

Optimize jQuery code

I've written this jQuery code that fades in a overlay with some links over an image. What i found out is that it is painfully slow when I add like 10 of these images. I would really appreciate some tips and tricks on how to make this code faster. If you have some tips for my HTML and CSS that would be great too ;) jQuery code $(docume...

My IN clause leads to a full scan of an index in T-SQL. What can I do?

I have a sql query with 50 parameters, such as this one. DECLARE @p0 int, @p1 int, @p2 int, (text omitted), @p49 int SELECT @p0=111227, @p1=146599, @p2=98917, (text omitted), @p49=125319 -- SELECT [t0].[CustomerID], [t0].[Amount], [t0].[OrderID], [t0].[InvoiceNumber] FROM [dbo].[Orders] AS [t0] WHERE ([t0].[CustomerID]) IN (...

Understanding Ruby on Rails render times

I am working on an "optimization" on my application and I am trying to understand the output that rails (version 2.2.2) gives at the end of the render. Here is the "old" way: Rendered user/_old_log (25.7ms) Completed in 466ms (View: 195, DB: 8) | 200 OK And the "new" way: Rendered user/_new_log (48.6ms) Completed in 337ms (View: 192...

How can adding code to a loop make it faster?

I have a simple function with an inner loop - it scales the input value, looks up an output value in a lookup table, and copies it to the destination. (ftol_ambient is a trick I copied from the web for fast conversion of float to int). for (i = 0; i < iCount; ++i) { iScaled = ftol_ambient(*pSource * PRECISION3); if (iScaled <=...

Most efficient way to convert a ISO Date into Unix timestamp?

In my application, I have some records which I need to filter based on some time parameters. To do the date comparisons, I need to convert the dates in my records (a string in the format YYYY-MM-DD), to a unix timestamp (seconds since 1970). Since I have many thousands of records, I really want to find the most efficient way to do it. A...

C/C++: Optimization of pointers to string constants

Have a look at this code: #include <iostream> using namespace std; int main() { const char* str0 = "Watchmen"; const char* str1 = "Watchmen"; char* str2 = "Watchmen"; char* str3 = "Watchmen"; cerr << static_cast<void*>( const_cast<char*>( str0 ) ) << endl; cerr << static_cast<void*>( const_cast<char*>( str1 ) )...

C# Micro-Optimization Query: IEnumerable Replacement

Note: I'm optimizing because of past experience and due to profiler software's advice. I realize an alternative optimization would be to call GetNeighbors less often, but that is a secondary issue at the moment. I have a very simple function described below. In general, I call it within a foreach loop. I call that function a lot (abo...

Flash Compiler/Interpreter Optimizations

I started working with ActionScript 3 / Flash 9 fairly recently, coming from a "real" programming background, and I have become a bit curious as to exactly what kind of machine code it ends up with at the end of the day. I would like to know what kind of optimizations the compiler makes when putting together the SWF with the optimize fl...

optimize time(NULL) call in c++

Hi, I have a system that spend 66% of its time in a time(NULL) call. It there a way to cache or optimize this call? Context: I'm playing with Protothread for c++. Trying to simulate threads with state machines. So Therefore I cant use native threads. Here's the header: #ifndef __TIMER_H__ #define __TIMER_H__ #include <time.h> #inc...