optimization

How to optimize a recursive algorithm to not repeat itself?

雨燕双飞 提交于 2020-01-04 05:45:09
问题 After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same areas in a sequence that a separate "search thread" may have also examined. The purpose of the diff module is to compute the difference and similarities between a

Very slow execution of for…in loop

断了今生、忘了曾经 提交于 2020-01-04 05:33:49
问题 I am populating a spreadhsheet from data I am getting from an external endpoint. Everything is working, but the execution of the for...in loop is incredibly slow. The object that I am getting back from UrlFetchApp is quite large; Object.keys().length > 1500 , so perhaps it could just be the size of the object. I am curious if there is a way to optimize my function. Code: var sh = SpreadsheetApp.getActiveSheet(); function getData() { var response = UrlFetchApp.fetch(endpoint); var data = JSON

Finding a multilanguage compiler or optimizer (c, c++, java)

瘦欲@ 提交于 2020-01-04 04:37:12
问题 In a nutshell, I am searching for a method to edit an open source compiler or optimizer to change traditional lock implementations to software transnational memory transactions. I have three target languages, C, C++, and Java. One idea might be to use GCC as it now has stm support. The problem is, I can't think of a way to implement these changes to the java bytecode dumped by GCJ. The same problem arises for llvm. tldr; trying to find a compiler or optimizer like gcc or llvm that I can

Does the VS2008 C++ optimizer sometimes produce slower code?

北战南征 提交于 2020-01-04 04:34:32
问题 Following on from a previous question, I've been playing around with optimizer settings in my release build to see what benefits are to be gleaned from using compiler optimization. Up until now, I've been using /Ob1 (only inline where inline is explicitly given), and /Oi (Enable intrinsic functions). I tried changing this to include /Ot (favour fast code), /Oy (omit frame pointers) and /Ob2 (inline any suitable), and to my surprise a regression suite that was taking 2h58 minutes now took

Running code AFTER the response has been sent by Koa

亡梦爱人 提交于 2020-01-04 04:30:28
问题 To optimize the response delay, it is necessary to perform work after are response has been sent back to the client. However, the only way I can seem to get code to run after the response is sent is by using setTimeout . Is there a better way? Perhaps somewhere to plug in code after the response is sent, or somewhere to run code asynchronously? Here's some code. koa = require 'koa' router = require 'koa-router' app = koa() # routing app.use router app app .get '/mypath', (next) -> # ...

Including an invariant assumption in a template function

点点圈 提交于 2020-01-04 04:23:26
问题 Consider a typical finite difference application: // assuming T_size > 2 void process_T(double *T0, double *T, const int &T_size, bool periodic) { for (int i = 0; i < T_size; ++i) { double sum = 0; double base = T0[i]; if (i > 0) sum += (T0[i-1]-base); if (i < 0) sum += (T0[i+1]-base); if (periodic) { if (i == 0) sum += (T0[T_size-1]-base); if (i == T_size-1) sum += (T0[0]-base); } else { if (i == 1 || i == T_size-1) sum += 0.5*(T0[i-1]-base); if (i == 0 || i == T_size-2) sum += 0.5*(T0[i+1]

Best way of minimizing simple objective in Matlab

不想你离开。 提交于 2020-01-04 04:14:05
问题 What is the best way of finding the shift along the x-axis for the blue line in this image such that it matches the red line? The result has to look like this image ). In MATLAB there are complex function like fminunc but I have to deal with some time constraints, so I'm wondering if there are more efficient ways. Edit: The data is coming from range measurements of an laser scan in a simulated environment. On the x-axis you see the bearing of each scan in radians versus the range measured in

How to optimize/simplify heapsorting django objects? (can't use modules and db sorts)

a 夏天 提交于 2020-01-04 04:09:18
问题 I have to ask for some help with an assignment I got as a test for a django internship. I had to make and imaginary api with rabbits and their carrots. Each rabbit was supposed to have a number of carrots, but the api had to be designed to allow for easy addition of other kind of vegetable. I rejected integer field for each vegetable and instead went for vegetable object with type and value of vegetable. Problem is, the assignment also included listing the rabbits sorted by carrots,

Shape, Sprite, MovieClip and other display objects: when to use?

此生再无相见时 提交于 2020-01-04 02:35:08
问题 there's a large ammount of display objects in flash.display package. It's not clear for me in what situation I should use Shape , Sprite or MovieClip . What is the pro and contras in using each of them? Thank you in advance!! 回答1: Shape is the simplest display object you can add on stage. It is the most limited one: you can't add childen to it (does not extend DisplayObjectContainer), does not have interactivity (does not extend InteractiveObject), does not have a timeline Sprite extends

Error in optim(): searching for global minimum for a univariate function

孤人 提交于 2020-01-04 02:04:09
问题 I am trying to optmize a function in R The function is the Likelihood function of negative binominal when estimating only mu parameter. This should not be a problem since the function clearly has just one point of maximum. But, I am not being able to reach the desirable result. The function to be optmized is: EMV <- function(data, par) { Mi <- par Phi <- 2 N <- NROW(data) Resultado <- log(Mi/(Mi + Phi))*sum(data) + N*Phi*log(Phi/(Mi + Phi)) return(Resultado) } Data is a vector of negative