optimization

C# 'is' type check on struct - odd .NET 4.0 x86 optimization behavior

Update: I have filed a bug report with Microsoft Connect, please vote for it! Update 2: Microsoft have marked the bug report as fixed Posted by Microsoft on 18/08/2010 at 17:25 This bug will be fixed in a future version of the runtime. I'm afraid it's too early to tell if that will be in a service pack or the next major...

Storing information in the DOM?

Im making a small private message application in the form of a phone. Ten messages are shown at the time. And the list of messages are scrolled up/down by hiding them. Just how bad is it to use the DOM to store information in this way. My main goal for doing this is to reduce calls to the database. And instead of making a new call all t...

Why would using a Temp table be faster than a nested query?

We are trying to optimise some of our queries. One query is doing the following: SELECT t.TaskID, t.Name as Task, '' as Tracker, t.ClientID, (<complex subquery>) Date, INTO [#Gadget] FROM task t SELECT TOP 500 TaskID, Task, Tracker, ClientID, dbo.GetClientDisplayName(ClientID) as Client FROM [#Gadget] order by CASE WHEN Date IS NULL...

What are the implications of running python with the optimize flag?

I cannot seem to find a good simple explanation of what python does differently when running with the -O or optimize flag. ...

Speed comparison - Template specialization vs. Virtual Function vs. If-Statement

Just to get it out of the way... Premature optimization is the root of all evil Make use of OOP etc. I understand. Just looking for some advice regarding the speed of certain operations that I can store in my grey matter for future reference. Say you have an Animation class. An animation can be looped (plays over and over) or not lo...

How can I check if I made optimal mysql database?

Are there any ways to check whether my Mysql database and PHP script are optimal? I want to figure it out and fix if it's possible till I publish it on internet for many users. Thanks. ...

C++ - How to efficiently find out if any string in a vector can be assembled from a set of letters

Hello, everyone! I am implementing a text-based version of Scrabble for a college project. I have a vector containing around 400K strings (my dictionary), and, at some point in every turn, I'm going to have to check if there's still a word in the dictionary which can be formed with the pieces in the player's hand. I'm checking if the p...

Alternate User select interface in django admin to reduce page size on large site?

I have a Django-based site with roughly 300,000 User objects. Admin pages for objects with a ForeignKey field to User take a very long time to load as the resulting form is about 6MB in size. Of course, the resulting dropdown isn't particularly useful, either. Are there any off-the-shelf replacements for handling this case? I've been go...

How does JIT replace optimized machine code during runtime?

I'm browsing through OpenJDK sources and cannot find the place where optimized code is replaced. I wonder how this can be done in protected mode, isn't it some kind of selfmodifing code which should be prevented by the OS? ...

Website optimization

Hi, have can i speed up the loading of images - specialy when i open the website for the first time it takes some time for images to load... Is there anything i can do to improve this (html, css)? link Thank to all for your answers. ...

optimization math computation (multiplication and summing)

Suppose you want to compute the sum of the square of the differences of items: $\sum_{i=1}^{N-1} (x_i - x_{i+1})^2$ the simplest code (the input is std::vector<double> xs, the ouput sum2) is: double sum2 = 0.; double prev = xs[0]; for (vector::const_iterator i = xs.begin() + 1; i != xs.end(); ++i) { sum2 += (prev - (*i)) * (prev - (...

Python optimization problem?

Alright, i had this homework recently (don't worry, i've already done it, but in c++) but I got curious how i could do it in python. The problem is about 2 light sources that emit light. I won't get into details tho. Here's the code (that I've managed to optimize a bit in the latter part): import math, array import numpy as np from PIL...

What is microbenchmarking?

I've heard this term used, but I'm not entirely sure what it means, so: What DOES it mean and what DOESN'T it mean? What are some examples of what IS and ISN'T microbenchmarking? What are the dangers of microbenchmarking and how do you avoid it? (or is it a good thing?) ...

Where is the virtual function call overhead?

Hello everybody, I'm trying to benchmark the difference between a function pointer call and a virtual function call. To do this, I have written two pieces of code, that do the same mathematical computation over an array. One variant uses an array of pointers to functions and calls those in a loop. The other variant uses an array of point...

Shall I optimize or let compiler to do that?

What is the preferred method of writing loops according to efficiency: Way a) /*here I'm hoping that compiler will optimize this code and won't be calling size every time it iterates through this loop*/ for (unsigned i = firstString.size(); i < anotherString.size(), ++i) { //do something } or maybe should I do it...

Django: Set foreign key using integer?

Is there a way to set foreign key relationship using the integer id of a model? This would be for optimization purposes. For example, suppose I have an Employee model: class Employee(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) type = models.ForeignKey('EmployeeType') ...

Optimizing Jaro-Winkler algorithm

I have this code for Jaro-Winkler algorithm taken from this website. I need to run 150,000 times to get distance between differences. It takes a long time, as I run on an Android mobile device. Can it be optimized more? public class Jaro { /** * gets the similarity of the two strings using Jaro distance. * * @param s...

Optimizing an iphone app for 3G in landscape with opengl, camera, quartz

I have an iphone app that basically uses the camera, an opengl layer, and UIViews (some drawing with Quartz). It runs ok on 3GS, but on the 3G it is unusable. Particularly, when I press a UIButton, it literally takes sometimes 10 seconds to register the press. Shark doesn't do me much good because it crashes when I try to profile even...

Is opening too many datacontexts bad?

I've been checking my application with linq 2 sql profiler, and I noticed that it opens a lot of datacontexts, most of them are opened by the linq datasource I used, since my repositories use only the instance stored in Request.Items, is it bad to open too many datacontext? and how can I make my linqdatasource to use the datacontext that...

how so select similarities in MySQL?

Currently, I am doing a search function. Lets say in my database, I have this data: Keyword1 Keyword2 Keyword3 Keysomething Key and the user entered: "Key" as the keyword to search. This is my current query: Q1: SELECT * FROM data WHERE (data_string LIKE '$key%' OR data_string LIKE '%$key%' OR data_string LIKE '...