Why is numpy.absolute() so slow?

I need to optimize a script that makes heavy use of computing L1 norm of vectors. As we know L1 norm in this case is just a sum of absolute values. When timing how fast numpy is in this task I found something weird: addition of all vector elements i...
more »

2017-10-01 15:10 (2) Answers

How to measure the quality of my code?

I have some experience with coding but one of the biggest questions which annoying me is how to improve my code. I every time check the complexity, readability and the correctness of the code but my question is how I can measure the size and the tim...
more »

2017-09-24 15:09 (3) Answers

ARM: Using cache memory to speed up critical code

Suppose that I have an embedded project (with an ARM Cortex-M if it makes a difference) where parts of the code are critical and need to run fast and in a deterministic time as much as possible. Would it be possible to sacrifice part of the L1 cach...
more »

2017-09-21 12:09 (1) Answers

Optimizing lazy collections

This question is about optimizing lazy collections. I will first explain the problem and then give some thoughts for a possible solution. Questions are in bold. Problem Swift expects operations on Collections to be O(1). Some operations, especially...
more »

2017-09-19 06:09 (2) Answers

Optimizing function speed on 3D array

I am applying a user-defined function to individual cells of a 3D array. The contents of each cell are one of the following possibilities, all of which are character vectors because of prior formatting: "N" "A" "" "1" "0" I want to create a new 3...
more »

2017-09-18 20:09 (1) Answers

Good key props for a list of rating stars

I have the following code to render 5 stars for a component. I want it always to be exactly 5 stars, but depending on the rating, the rest of the stars should be blank. I have the following code to achieve this.: const stars = [] for (let i = 0; i &...
more »

2017-09-09 13:09 (1) Answers

Integer powers in C

In C code it is common to write a = b*b; instead of a = pow(b, 2.0); for double variables. I get that since pow is a generic function capable of handling non-integer exponents, one should naïvely think that the first version is faster. I wonde...
more »

2017-09-04 17:09 (1) Answers

How to reduce code of multiple if statements

I am trying to validate a large contact form. When the user forgets a required input field then I populate the empty variable with default text. My current solution uses nine if statements. Is there a better way to do it with less code? html: &l...
more »

2017-09-03 09:09 (3) Answers

Code Optimization issue

I am doing some code changes in Android development to make my coding more accurate. I have 7 TextViews in my layout for all week days, i have done find view by id for all those TextViews. The requirement is that only one TextView should remain sele...
more »

2017-08-28 14:08 (1) Answers

Mac OSX minumum support sse version

What is the minimum supported sse flag that can be enabled on osx?. most of hardware, I uses supports sse2 these days. On windows and linux, I have some code to test sse support. I read somewhere that osx has support for sse for long time. But I don...
more »

2017-08-28 12:08 (1) Answers

STMP MX lookup faster solution

I'm looking for a solution, how can I validate existence of an email address. I found one that works, but it is very slow. At some addresses it returns in 500 ms but mostly more than 2000-3000 ms, sometimes raised to 5000 ms. The application wher...
more »

2017-08-21 13:08 (0) Answers

Code optimisation: Arrays vs collections

In terms of memory consumption/ execution time, what's a more expensive way of adding items to a group Redim Preserve myArray(1 To Ubound(myArray) + 1) myArray(Ubound(myArray)) = myVal Or myCollection.Add myVal Does the fastest one depend on my...
more »

2017-08-17 18:08 (1) Answers

Why isn't python optimising this code?

Consider: Code A def foo(): pass for i in range(1000000): foo() Code B for i in range(1000000): def foo(): pass foo() The only difference between the two code snippets are that foo is constantly redefined inside the ...
more »

2017-08-17 09:08 (4) Answers

Solving for two parameters using `optim()` in R?

I'm trying to find shape1 and shape2 in dbeta() such that the answer from dbeta() for the two input values: .6 and .8 become 3. I'm using the below optim() but don't get exact result, that is I expect getting values for shape1 and shape2 that when u...
more »

2017-08-15 01:08 (0) Answers