optimization

Best way to store commonly used values

In my Webforms 3.5 application, I have a GridView of users that displays the last time they logged in. This value is stored in the Users table in UTC. When an Administrator views the grid, I want them to view it the time zone the Administrator has selected in their preferences (also stored in the Users table). I have this working prop...

How do I profile and optimize an XSLT?

I have an XSLT for viewing XML files in the browser. The XSLT is naively written and currently takes a long time to execute (several minutes). My XML file is of modest size (~1 MiB), and other XSLTs for the same document that do different processing execute much more quickly. So I know it isn't the size of the XML that is the problem,...

Is website content partitioning worth while?

In order to allow for multiple policies regarding content... security, cookies, sessions, etc, I'm considering moving some content from my sites to their own domains and was wondering what kinds of dividends it will pay off (If any). I understand cookies are domain specific and are sent on every request (even for images) so if they gro...

How to correctly benchmark a [templated] C++ program

Hi, < backgound> I'm at a point where I really need to optimize C++ code. I'm writing a library for molecular simulations and I need to add a new feature. I already tried to add this feature in the past, but I then used virtual functions called in nested loops. I had bad feelings about that and the first implementation proved that th...

Are constant C expressions evaluated at compile time or at runtime?

If I write a #define that performs an operation using other preprocessor constants, is the final value computed each time the macro appears at runtime? Does this depend on optimizations in the compiler, or is it covered under a standard? Example: #define EXTERNAL_CLOCK_FREQUENCY 32768 #define TIMER_1_S EXTERNAL_CLO...

How do I optimize my stored procedure?

I ran a profiler today and found that one of my stored procedures is taking a very high CPU read (1899999) and duration (3233333). How can I fix this problem? ...

Linear Programming Problem with Complication

I'm trying to solve a problem that looks like a standard Linear Programming problem with one twist. We have as input a set of "phrases" each of which has a weight. We need to choose how many times to repeat each phrase in a text to maximize the total weight, subject to a max character length limitation. This seems like a straightforwa...

What are some optimization techniques for MySQL table with 300+ million records?

I am looking at storing some JMX data from JVMs on many servers for about 90 days. This data would be statistics like heap size and thread count. This will mean that one of the tables will have around 388 million records. From this data I am building some graphs so you can compare the stats retrieved from the Mbeans. This means I w...

SQL - Use results of a query as basis for two other queries in one statement

I'm doing a probability calculation. I have a query to calculate the total number of times an event occurs. From these events, I want to get the number of times a sub-event occurs. The query to get the total events is 25 lines long and I don't want to just copy + paste it twice. I want to do two things to this query: calculate the numb...

Is it ok to use character values for primary keys?

Is there a performance gain or best practice when it comes to using unique, numeric ID fields in a database table compared to using character-based ones? For instance, if I had two tables: athlete id ... 17, name ... Rickey Henderson, teamid ... 28 team teamid ... 28, teamname ... Oakland The athlete table, with thousands of playe...

C# compiler and caching of local variables

EDIT: Oops - as rightly pointed out, there'd be no way to know whether the constructor for the class in question is sensitive to when or how many times it is called, or whether the object's state is changed during the method, so it would have to be created from scratch each time. Ignore the Dictionary and just consider delegates created ...

Why is Math.DivRem so inefficient

In my computer this code takes 17 seconds (1000 millons times) static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); int r; for (int i = 1; i <= 100000000; i++) { for (int j = 1; j <= 10; j++) { MyDivRem (i,j, out r); } } Console.WriteLine(sw.ElapsedMilliseconds); } static int MyDiv...

Virtual functions and performance - C++

In my class design, I use abstract classes and virtual functions extensively. I had a feeling that virtual functions affects the performance. Is this true? But I think this performance difference is not noticebale and looks like I am doing premature optimization. Right? ...

Is there already some std::vector based set/map implementation?

For small sets or maps, it's usually much faster to just use a sorted vector, instead of the tree-based set/map - especially for something like 5-10 elements. LLVM has some classes in that spirit, but no real adapter that would provide a std::map like interface backed up with a std::vector. Any (free) implementation of this out there? ...

Why does my VB.NET class library show "My" and "My.Resources" namespaces in Reflector?

I have no intention of using "My" for anything in any of my projects. I haven't done anything with it (that I know of). But every one of class libraries shows a "My" namespace in Reflector and NDepend. This adds a lot of unnecessary clutter. 1) Why does it show up? 2) How can I remove it? ...

ActionScript 2 boxing performance

I heard that AS boxes and un-boxes values every time arguments are passed into/out of functions. A. Therefore, would this be faster? var val = doWork(50,"hello", 2048); function doWork (param1,param2,param3){ t.text = param2; return param1+param3; } B. Or this? var val:Number = doWork(50,"hello", 2048); function doWork (para...

What's the most efficient way to share large amounts of data between Python and C++

I'm writing a system that allows python scripts to be executed within a C++ application. The python scripts are used to modify values within arrays of data (typically 2048x2048x4 arrays of floats) I'm currently using numpy arrays created using the array API and registered with Python. In the python scripts I'm accessing the arrays l...

Does adding 'LIMIT 1' to MySQL queries make them faster when you know there will only be 1 result?

When I add LIMIT 1 to a MySQL query, does it stop the search after it finds 1 result (thus making it faster) or does it still fetch all of the results and truncate at the end? ...

Does restrict help in C if a pointer is already marked const?

Just wondering: When I add restrict to a pointer, I tell the compiler that the pointer is not an alias for another pointer. Let's assume I have a function like: // Constructed example void foo (float* result, const float* a, const float* b, const size_t size) { for (size_t i = 0; i < size; ++i) { result [i] = a [0] * ...

I need a fast key substitution algorithm for java

Given a string with replacement keys in it, how can I most efficiently replace these keys with runtime values, using Java? I need to do this often, fast, and on reasonably long strings (say, on average, 1-2kb). The form of the keys is my choice, since I'm providing the templates here too. Here's an example (please don't get hung up on...