optimization

C/C++ optimize data structures, array of arrays or just array

Working with a program that uses 16bytes 4v4 one byte matrices : unsigned char matrix[4][4]; and a few 256bytes 16v16 one byte matrices: unsigned char bigMatrix[16][16]; Very often due to data manipulation I am forced to loop column wise in the program making cache misses. Will the performance improve if I use an array instead, i....

C/C++ best way to send a number of bytes to stdout

Profiling my program and the function print is taking a lot of time to perform. How can I send "raw" byte output directly to stdout instead of using fwrite, and making it faster (need to send all 9bytes in the print() at the same time to the stdout) ? void print(){ unsigned char temp[9]; temp[0] = matrix[0][0]; temp[1] = ma...

What is Python's "built-in method acquire"? How can I speed it up?

I'm writing a Python program with a lot of file access. It's running surprisingly slowly, so I used cProfile to find out what was taking the time. It seems there's a lot of time spent in what Python is reporting as "{built-in method acquire}". I have no idea what this method is. What is it, and how can I speed up my program? ...

.NET Optimized Int32

While reading through the 70-536 training kit, it states: The runtime optimizes the performance of 32-bit integer types (Int32), so use those types for counters and other frequently accessed integral variables. Does this only apply in a 32 bit environment? Does Int64 take over in a 64 bit environment, or is Int32 still th...

Any way to make this relatively simple (nested for memory copy) C++ code more effecient?

I realize this is kind of a goofy question, for lack of a better term. I'm just kind of looking for any outside idea on increasing the efficiency of this code, as it's bogging down the system very badly (it has to perform this function a lot) and I'm running low on ideas. What it's doing it loading two image containers (imgRGB for a fu...

Optmizing MySQL GROUP BY or DISTINCT on large views

Consider a view consisting of several tables... for example a v_active_car, which is made up of the tables car joined on to body, engine, wheels and stereo. It might look something like this: v_active_cars view SELECT * FROM car INNER JOIN body ON car.body = body.body_id INNER JOIN engine ON car.engine = engine.engine_id I...

What algorithm can I use to determine points within a semi-circle?

I have a list of two-dimensional points and I want to obtain which of them fall within a semi-circle. Originally, the target shape was a rectangle aligned with the x and y axis. So the current algorithm sorts the pairs by their X coord and binary searches to the first one that could fall within the rectangle. Then it iterates over e...

Can I control register allocation in g++?

I have highly optimized piece of C++ and making even small changes in places far from hot spots can hit performance as much as 20%. After deeper investigation it turned out to be (probably) slightly different registers used in hot spots. I can control inlineing with always_inline attribute, but can I control register allocation? ...

File Copying optimization through multiple threads

Can you make file copying faster through multiple threading? Edit: To clarify, suppose you were implementing CopyFile(src, tgt). It seems logical that under certain circumstances you could use multiple threads to make it go faster. Edit Some more thoughts: Naturally, it depends on the HW/storage in question. If you're copying from on...

Handling very large numbers in Python

I've been considering fast poker hand evaluation in Python. It occurred to me that one way to speed the process up would be to represent all the card faces and suits as prime numbers and multiply them together to represent the hands. To whit: class PokerCard: faces = '23456789TJQKA' suits = 'cdhs' facePrimes = [11, 13, 17, 1...

What is code optimization?

When said this code need some optimization, or can be some how optimized, what does that mean? which kind of code need optimization? How to apply optimization to the code in c#? What the benefits from that? ...

SQL: Select records belonging to excluded category that ONLY belong to excluded category

I have a SELECT statement that works, and runs fast enough on my tables (<0.01sec on 50k+ products, 3k+ categories). But in my mind it's not very elegant and would like to hear any suggestions on making it better. There are 3 tables of interest: products - key productID categories - key categoryID products_tree - link table (...

Solving nonlinear equations numerically

Hello, I need to solve nonlinear minimization (least residual squares of N unknowns) problems in my Java program. The usual way to solve these is the Levenberg-Marquardt algorithm. I have a couple of questions Does anybody have experience on the different LM implementations available? There exist slightly different flavors of LM, and ...

optimize SQL query

What more can I do to optimize this query? SELECT * FROM (SELECT `item`.itemID, COUNT(`votes`.itemID) AS `votes`, `item`.title, `item`.itemTypeID, `item`. submitDate, `item`.deleted, `item`.ItemCat, `item`.counter, `item`.userID, `users`.name, TIMESTAMPDIFF(minute,`submitDate`,NOW()) AS 'timeMin' , ...

How to optimize this code?

Surely there has to be many ways to optimize the following code, where I basically have to make sure that a lot of textboxes aren't empty and then read their values: if (foo1.Text.Length != 0 & bar1.Text.Length != 0) { output.Text += myStrings[i] + " / " + foo1.Text + " / " + bar1.Text; } if (foo2.Text.Length != 0 & bar2.Text.Lengt...

Does visibility affect DOM manipulation performance?

IE7/Windows XP I have a third party component in my page that does a lot of DOM manipulation to adjust itself each time the browser window is resized. Unfortunately I have little control of what it does internally and I have optimized everything else (such as callbacks and event handlers) as much as I can. I can't take the component of...

Biggest performance improvement you've had with the smallest change?

What's the biggest performance improvement you've had with the smallest change? For example, I once improved the performance of a certain page on a high-profile web app by a factor of 10, just by moving "where customerID = ?" to a different place inside a complicated SQL statement (before my change it had been selecting all customers in...

How to optimize query looking for rows where conditional join rows do not exist?

I've got a table of keywords that I regularly refresh against a remote search API, and I have another table that gets a row each each time I refresh one of the keywords. I use this table to block multiple processes from stepping on each other and refreshing the same keyword, as well as stat collection. So when I spin up my program, it qu...

How do I write (test) code that will not be optimized by the compiler/JIT?

I don't really know much about the internals of compiler and JIT optimizations, but I usually try to use "common sense" to guess what could be optimized and what couldn't. So there I was writing a simple unit test method today: @Test // [Test] in C# public void testDefaultConstructor() { new MyObject(); } This method is actually ...

Preloading Assemblies

At work we use DevExpress for the user interface. The first time a form employing a DevExpress control is opened there's a long pause (sometimes 15-20 sec on some clients). In Visual Studio i can see that tons of assemblies are being loaded during that phase. Is there a way to preload that assemblies into the AppDomain in the background ...