optimization

Prevent unnecessary copies of C++ functor objects

I have a class which accumulates information about a set of objects, and can act as either a functor or an output iterator. This allows me to do things like: std::vector<Foo> v; Foo const x = std::for_each(v.begin(), v.end(), Joiner<Foo>()); and Foo const x = std::copy(v.begin(), v.end(), Joiner<Foo>()); Now, in theory, the compil...

How to increase my program speed

i stored data in two different google spreadsheet.one spreadsheet have nearly 1000 entries.I used another spreadsheet to give input .My constraints is compare these two spreadsheet and if common data appear in two spreadsheet than put that data into another spreadsheet.So that i used for loop to compare these two. My problem is that it...

Specific Path Algorithm with Speed Considered

I need to create an algorithm where a "vehicle" covers a 1262 m x 1262 m area with 20% overlap between each "leg". The width of each leg is 103 m, which by my calculations gives 16 "legs" needed to cover this area. At the end of each leg, the vehicle does a 180 degree turn, and completes the next search leg. The vehicle is traveling a...

[Optimize This]: Slow LINQ to Objects Query

I have this query that is bothering me; it is encapsulated as a new query operator, I made two versions of it, trying to see which one performs better. Both perform horribly. First attempt; declarative style public static IEnumerable<IEnumerable<α>> Section<α>(this IEnumerable<α> source, int length) { return source.Any() ? ...

How can I optimize my C / x86 code?

int lcm_old(int a, int b) { int n; for(n=1;;n++) if(n%a == 0 && n%b == 0) return n; } int lcm(int a,int b) { int n = 0; __asm { lstart: inc n; mov eax, n; mov edx, 0; idiv a; mov eax, 0; cmp eax, edx; jne lstart; mov eax, n; mo...

Does Quartz for iPhone draw non visible portions of a view?

Hi folks, I am wondering which is the best way, in terms of speed and efficiency, to draw a frame around an image on iPhone, especially when I have to draw lots of these images: 1) Drawing the image and then the frame around or 2) Drawing a rect, filling it with a color and then drawing the image within that rect leaving some offset pi...

performance consideration when using properties multiple times

I am using CultureInfo.CurrentCulture when formating my strings using string.format To quote this blog This just has the implication that if you are using CurrentCulture a lot, it might be worth reading it into a private variable rather than making lots of calls to CultureInfo.CurrentCulture, otherwise you're using up cl...

PHP Optimize Function in Loop

I am micro-optimizing this function and have a bit of a problem where inside a loop I am checking if a value outside of the loop is 0, if so call function and similarly in the function it calls. How would I refactor it so there is no conditional logic (which is slow) inside these loops. foreach($this->layer[$l]->objs as $obj) { //H...

Check if Services/APIs have Expired Their Content - Best Practices for Optimizing/Caching Service Usage?

If you want to build a website/mashup using 10+ services (twitter, facebook, linkedin, github, stackoverflow, etc.), and you also want to optimize your application... Can you check if a URL's content is expired, without having to GET all of the pages content? If you could do that, then you could keep a local cache of their content in y...

SQL queries running slowly or stuck after DBCC DBReindex or Alter Index

All, SQL 2005 sp3, database is about 70gb in size. Once in a while when I reindex all of my indexes in all of my tables, the front end seems to freeze up or run very slowly. These are queries coming from the front end, not stored procedures in sql server. The front end is using JTDS JDBC connection to access the SQL Server. If we stop a...

Optimizing HttpWebResponse - GetResponse

I'm using the following lines of code to read the response of an asynchronous HttpWebRequest. This seems to be the largest amount of time spent in a particular operation. Is there anything I can optimize here? System.Net.HttpWebResponse oResp =(System.Net.HttpWebResponse)oReq.EndGetResponse(oResult); oResp = (HttpWebResponse)oReq.GetRes...

Slow writing to array in C++

Hi everyone, I was just wondering if this is expected behavior in C++. The code below runs at around 0.001 ms: for(int l=0;l<100000;l++){ int total=0; for( int i = 0; i < num_elements; i++) { total+=i; } } However if the results are written to an array, the time of execution shoots up t...

What causes page fault and how to minimize them?

When examining a process in Process Explorer, what does it mean when there are several page faults? The application is processing quite a bit of data and the UI is not very responsive. Are there optimizations to the code that could reduce or eliminate page faults? Would increasing the physical RAM of the system make a difference? ...

Use a db.StringProperty() as unique identifier in Google App Engine

Hi, I just have a hunch about this. But if feels like I'm doing it the wrong way. What I want to do is to have a db.StringProperty() as a unique identifier. I have a simple db.Model, with property name and file. If I add another entry with the same "name" as one already in the db.Model I want to update this. As of know I look it up w...

Tracking power use on Android

I have an application that keeps a long-standing network connection to a server. I periodically ping the server to know if its still alive. I imagine that it affects battery life, but other than trying to wall-clock time the time between charges, I don't have a good way of quantifying this. Is there a mechanism for being told when the...

Optimisation of Ruby algorithm for grouping and counting colours.

Hi, i have what seems on the surface a simple problem which i wish to solve using ruby, i have a bunch of colours with associated photo id's, e.g [[1,"red"],[1,"green"],[2,"red"],[3,"yellow"],[4,"green"],[4,"red"]] and i wish to process the data so that it is in this format: 2 photos for red,green 3 photos for red 1 photo for yellow ...

C or C++ for OpenGL graphics

Hi, there is any drawback in choose C++ and an object oriented model (classes) to implement a simulation in OpenGL (or DirectX)? It's preferred to use C and a procedural programming paradigm ? ...

Storing frequently accessed data in a file rather than MySQL

I'm working on a PHP content management system and, in testing, have noticed that quite a few of the system's MySQL tables are queried on almost every page but are very rarely written to. What I'm wondering is will this start to weigh heavily on the database as site traffic increases, and how can I solve/prevent this? My initial thought...

If statements inside or outside loops?

Is it better if I do this: foreach my $item ( @array ) { if ( $bool ) { .. code .. } else { .. code .. } } or if ( $bool ) { foreach my $item ( @array ) { } } else { foreach my $item ( @array ) { } } ...

Alternative approaches to a complicated-ish query in an badly-designed schema

I'm working on integrating some data from a 3rd-Party system into one of my applications (legacy ASP Classic-based web application/SQL 2000) - they have made some poor decisions (IMHO) when it comes to their approach and data structure, though perhaps we might get a chance to refactor at some point... but until then, I have to work with ...