optimization

i++ less efficient than ++i, how to show this?

你说的曾经没有我的故事 提交于 2019-12-28 04:13:31
问题 I am trying to show by example that the prefix increment is more efficient than the postfix increment. In theory this makes sense: i++ needs to be able to return the unincremented original value and therefore store it, whereas ++i can return the incremented value without storing the previous value. But is there a good example to show this in practice? I tried the following code: int array[100]; int main() { for(int i = 0; i < sizeof(array)/sizeof(*array); i++) array[i] = 1; } I compiled it

Does GCC inline C++ functions without the 'inline' keyword?

◇◆丶佛笑我妖孽 提交于 2019-12-28 03:57:44
问题 Does GCC, when compiling C++ code, ever try to optimize for speed by choosing to inline functions that are not marked with the inline keyword? 回答1: Yes. Any compiler is free to inline any function whenever it thinks it is a good idea. GCC does that as well. At -O2 optimization level the inlining is done when the compiler thinks it is worth doing (a heuristic is used) and if it will not increase the size of the code. At -O3 it is done whenever the compiler thinks it is worth doing, regardless

Speed up adding objects to Canvas In WPF

故事扮演 提交于 2019-12-28 03:04:29
问题 I have a Canvas that I am using in WPF to draw many colored rectangles to but the program is running really slow when they are being added. I have tried different options, such as adding them to an Array and adding them all at once and using a Image instead of a Canvas to dispay them, but they didn't seem to do much. I have the coding leading up the drawing in a thread, but because of C# rules, I have to have the drawing part in the main thread. I should also note that the problem isn't my

Speed up adding objects to Canvas In WPF

ε祈祈猫儿з 提交于 2019-12-28 03:04:06
问题 I have a Canvas that I am using in WPF to draw many colored rectangles to but the program is running really slow when they are being added. I have tried different options, such as adding them to an Array and adding them all at once and using a Image instead of a Canvas to dispay them, but they didn't seem to do much. I have the coding leading up the drawing in a thread, but because of C# rules, I have to have the drawing part in the main thread. I should also note that the problem isn't my

sorted() using Generator Expressions Rather Than Lists

落花浮王杯 提交于 2019-12-28 02:49:08
问题 After seeing the discussion here: Python - generate the time difference I got curious. I also initially thought that a generator is faster than a list, but when it comes to sorted() I don't know. Is there any benefit to sending a generator expression to sorted() rather than a list? Does the generator expression end up being made into a list inside sorted() before sorting anyway? EDIT: It grieves me to only be able to accept one answer, as I feel a lot of responses have helped to clarify the

How to reduce the size of executable produced by MinGW g++ compiler?

孤者浪人 提交于 2019-12-28 02:12:05
问题 I have a trivial "Hello world" C++ program that is compiled to 500kB executable by MinGW g++ compiler under Win XP. Some say that is caused by iostream library and static link of libstdc++.dll . Using -s linker option helped a bit (reducing 50% size), but I would by satisfied only by <10kB executable. Is there any way how to achieve this using MinGW compiler? Portability is not a big concern for me. Is it possible to copy libstdc++.dll with the executable using dynamic linking? If so, how to

how to optimize matrix multiplication (matmul) code to run fast on a single processor core

谁说我不能喝 提交于 2019-12-28 02:11:09
问题 I am working on parallel programming concepts and trying to optimize matrix multiplication example on single core. The fastest implementation I came up so far is the following: /* This routine performs a dgemm operation * C := C + A * B * where A, B, and C are lda-by-lda matrices stored in column-major format. * On exit, A and B maintain their input values. */ void square_dgemm (int n, double* A, double* B, double* C) { /* For each row i of A */ for (int i = 0; i < n; ++i) /* For each column

Most efficient way of converting String to Integer in java

独自空忆成欢 提交于 2019-12-28 02:08:08
问题 There are many ways of converting a String to an Integer object. Which is the most efficient among the below: Integer.valueOf() Integer.parseInt() org.apache.commons.beanutils.converters.IntegerConverter My usecase needs to create wrapper Integer objects...meaning no primitive int...and the converted data is used for read-only. 回答1: Don't even waste time thinking about it. Just pick one that seems to fit with the rest of the code (do other conversions use the .parse__() or .valueOf() method?

How to split/partition a dataset into training and test datasets for, e.g., cross validation?

♀尐吖头ヾ 提交于 2019-12-28 01:42:28
问题 What is a good way to split a NumPy array randomly into training and testing/validation dataset? Something similar to the cvpartition or crossvalind functions in Matlab. 回答1: If you want to split the data set once in two halves, you can use numpy.random.shuffle , or numpy.random.permutation if you need to keep track of the indices: import numpy # x is your dataset x = numpy.random.rand(100, 5) numpy.random.shuffle(x) training, test = x[:80,:], x[80:,:] or import numpy # x is your dataset x =

Beyond Stack Sampling: C++ Profilers

谁都会走 提交于 2019-12-28 01:38:12
问题 A Hacker's Tale The date is 12/02/10. The days before Christmas are dripping away and I've pretty much hit a major road block as a windows programmer. I've been using AQTime, I've tried sleepy, shiny, and very sleepy, and as we speak, VTune is installing. I've tried to use the VS2008 profiler, and it's been positively punishing as well as often insensible. I've used the random pause technique. I've examined call-trees. I've fired off function traces. But the sad painful fact of the matter is