optimization

Can HotSpot inline lambda function calls?

纵然是瞬间 提交于 2020-01-02 03:11:41
问题 Considering the code: someList.forEach(x -> System.out.format("element %s", x)); Theoretically, it should be possible to inline this code and eliminate the indirect function calls by first inlining the forEach method, and then inlining the lambda function body in the inlined forEach code. Is HotSpot capable of performing this optimization? What restrictions govern whether or not it is performed in a particular situation? 回答1: Your lambda expression is compiled into an ordinary method, while

Optimising C++ 2-D arrays

為{幸葍}努か 提交于 2020-01-02 02:35:11
问题 I need a way to represent a 2-D array (a dense matrix) of doubles in C++, with absolute minimum accessing overhead. I've done some timing on various linux/unix machines and gcc versions. An STL vector of vectors, declared as: vector<vector<double> > matrix(n,vector<double>(n)); and accessed through matrix[i][j] is between 5% and 100% slower to access than an array declared as: double *matrix = new double[n*n]; accessed through an inlined index function matrix[index(i,j)] , where index(i,j)

Optimize conversion between list of integer coefficients and its long integer representation

若如初见. 提交于 2020-01-02 02:28:33
问题 I'm trying to optimize a polynomial implementation of mine. In particular I'm dealing with polynomials with coefficients modulo n (might be >2^64 ) and modulo a polynomial in the form x^r - 1 ( r is < 2^64 ). At the moment I represent the coefficient as a list of integers(*) and I've implemented all the basic operations in the most straightforward way. I'd like the exponentiation and multiplication to be as fast as possible, and to obtain this I've already tried different approaches. My

May there be any penalties when using 64/32-bit registers in Long mode?

断了今生、忘了曾经 提交于 2020-01-02 02:01:11
问题 Probably this is all about not even micro- but nanooptimizations, but the subject interests me and I would like to know if there are any penalties when using non-native register sizes in long mode? I've learned from various sources, that partial register updates (like ax instead of eax ) can cause eflags stall and degrade performance. But I'm not sure about the long mode. What register size is considered native for this processor operation mode? x86-64 are still extensions to x86 architecture

Does gcc optimize my cycle with condition?

我是研究僧i 提交于 2020-01-02 01:54:07
问题 I have the following cycle: //condition will be set here to true or false for (int i = 0; i < LARGE_NUMBER; i++) { if (condition) { //do foo } else { //do bar } } Assumption: A cycle if faster without a condition than with a condition. (Is this true?) Question: Will gcc factor out my if , if condition has been set outside the for cycle, and the cycle itself doesn't touch condition ? If not, I should switch the if and the for , duplicate code, violate DRY, etc. 回答1: For those who don't wish to

Are preg_match() and preg_replace() slow?

徘徊边缘 提交于 2020-01-02 01:44:08
问题 I've been coding in PHP for a while and I keep reading that you should only use preg_match and preg_replace when you have to because it slows down performance. Why is this? Would it really be bad to use 20 preg_matches in one file instead of using another PHP function. 回答1: As Mike Brant said in his answer: There's nothing wrong with using any of the preg_* functions, if you need them. You want to know if it's a good idea to have something like 20 preg_match calls in a single file, well,

Optimising this C (AVR) code

风流意气都作罢 提交于 2020-01-02 01:15:11
问题 I have an interrupt handler that just isn't running fast enough for what I want to do. Basically I'm using it to generate sine waves by outputting a value from a look up table to a PORT on an AVR microncontroller but, unfortunately, this isn't happening fast enough for me to get the frequency of the wave that I want. I was told that I should look at implementing it in assembly as the compiler generated assembly might be slightly inefficient and may be able to be optimised but after looking at

What is pessimization?

﹥>﹥吖頭↗ 提交于 2020-01-02 00:55:12
问题 There is a comment on the question Can the use of C++11's auto improve performance? that scored many votes and suggests “makes it less likely to unintentionally pessimize” as an answer. I've never noticed this term before. I guess it is somehow the opposite of optimization. Can anyone give a more detailed definition? What does it mean in the context of programming? How would pessimized code look like? 回答1: It's mostly a play on words, a pessimist is the opposite of an optimist. And

How to optimize a query with multiple OR, AND, IN statements?

你。 提交于 2020-01-01 22:06:28
问题 I have a an SQL query as below: Declare @ConnectionType int = 5, @UserId int = 2 select * from CallDetails Where ((@ConnectionType = 0 AND CallDetails.DeviceType IN (0,1,2,3,4,5,7,8)) OR (@ConnectionType = 1 AND CallDetails.DeviceType = 4) OR (@ConnectionType = 2 AND CallDetails.DeviceType IN (0,1,2,3,7)) OR (@ConnectionType = 3 AND CallDetails.DeviceType = 5) OR (@ConnectionType = 4 AND CallDetails.DeviceType IN (0,1,2,3,4,7)) OR (@ConnectionType = 5 AND CallDetails.DeviceType IN (4,5)) OR (

Optimizing a comparison over array elements with two conditions; C++ abstraction mechanisms?

孤街醉人 提交于 2020-01-01 19:28:12
问题 My question is a follow-up to How to make this code faster (learning best practices)?, which has been put on hold (bummer). The problem is to optimize a loop over an array with floats which are tested for whether they lie within a given interval. Indices of matching elements in the array are to be stored in a provided result array. The test includes two conditions (smaller than the upper threshold and bigger than the lower one). The obvious code for the test is if( elem <= upper && elem >=