optimization

Simple MySQL Subquery Performance

 ̄綄美尐妖づ 提交于 2019-12-24 18:45:06
问题 Consider the 2 MySQL queries: SELECT ue.userid,e.courseid FROM (SELECT id,courseid FROM mdl_enrol WHERE status = 0 AND courseid IN (46)) e INNER JOIN (SELECT enrolid,userid FROM mdl_user_enrolments ) ue ON ue.enrolid = e.id INNER JOIN (SELECT userid FROM mdl_userdata) ud ON ue.userid = ud.userid -- SELECT ue.userid,e.courseid FROM mdl_enrol e INNER JOIN mdl_user_enrolments ue ON ue.enrolid = e.id INNER JOIN mdl_userdata ud ON ue.userid = ud.userid WHERE e.status = 0 AND e.courseid IN (46) The

Using a selection sort to sort an array in python. How can I optimize?

℡╲_俬逩灬. 提交于 2019-12-24 18:43:11
问题 Working on this challenge on HackerRank and got this code to pass 10 out of 15 test cases. It is failing due to timeout error which is HackerRank's way of telling you that the algorithm is not optimized. How can I optimize this code to run on larger input data? The goal is to figure out the minimum number of swaps necessary to sort an unsorted array. Update : Each element in the array is distinct. def minimum_swaps(arr): """Returns the minimum number of swaps to re-oder array in ascending

Java: Fastest way to draw text?

廉价感情. 提交于 2019-12-24 18:39:55
问题 I'm trying to write a program that just creates an image out of text (e.g. write "hello" on a white square and store the image), which sounds simple but it must be done quickly. I tried the Java2D library but drawing onto a BufferedImage takes ~2 seconds to just draw the image, not even save or display it. I also tried Java-based CAPTCHA generators but they take much too long (5 seconds). This seems like simple enough task to just draw text, but I'm frustrated that I can't do this faster than

Scipy Minimize - Unable to minimize objective function

谁都会走 提交于 2019-12-24 18:33:01
问题 I am trying to optimise a function to find max value of rev_tot using scipy minimise. Here obj_data is a list of probabilities, prem is a constant and inc can take any real value. Following is the code I have written for the objective function : import numpy as np import pandas as pd import scipy from scipy.optimize import minimize def objective(x,*args): prem = args[0] prob = args[1] inc = x[0] rev_tot = 0 rev = 0 del_p = 0.2*(1-np.exp(-2*(1-np.exp(-inc/400)))) for i in range(len(prob)): rev

How to increase query speed in db4o?

£可爱£侵袭症+ 提交于 2019-12-24 18:21:39
问题 OutOfMemoryError caused when db4o databse has 15000+ objects My question is in reference to my previous question (above). For the same PostedMessage model and same query. With 100,000 PostedMessage objects, the query takes about 1243 ms to return first 20 PostedMessages. Now, I have saved 1,000,000 PostedMessage objects in db4o. The same query took 342,132 ms. Which is non-linearly high. How can I optimize the query speed? FYR: The timeSent and timeReceived are Indexed fields. I am using

Comparison of Explain Statement Output on Amazon Redshift

风格不统一 提交于 2019-12-24 18:13:31
问题 I have written a very complicated query in Amazon Redshift which comprises of 3-4 temporary tables along with sub-queries.Since, Query is slow in execution, I tried to replace it with another query, which uses derived tables instead of temporary tables. I just want to ask, Is there any way to compare the " Explain " Output for both the queries, so that we can conclude which query is working better in performance(both space and time ). Also, how much helpful is replacing temporary tables with

optimizing regex to fine key=value pairs, space delimited

a 夏天 提交于 2019-12-24 18:11:27
问题 shortend URL with my current regex in regexpal: http://bit.ly/1jbOFGd I have a line of key=value pairs, space delimited. Some values contain spaces and punctuation so I do a positive lookahead to check for the existence of another key. I want to tokenize the key and value, which I later convert to a dict in python. My guess is that I can speed this up by getting rid of .*? but how? In python I convert 10,000 of these lines in 4.3 seconds. I'd like to double or triple that speed by making this

Is it better to glClear() before drawing to a buffer or after?

微笑、不失礼 提交于 2019-12-24 18:07:58
问题 I currently have code that does the following: sleep until next frame glClear(GL_COLOR_BUFFER_BIT | GL_DPETH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); perform all drawing for the frame flush and display drawing to screen sleep until next frame (again) My question is: should the clear (2) be moved to happen after step 4? This order is nice because it's easier to prep a render buffer for rendering conceptually, like putting primer on a canvas, as opposed to cleaning the render buffer up afterwards.

lookup table vs runtime computation efficiency - C++

删除回忆录丶 提交于 2019-12-24 17:19:28
问题 My code requires continuously computing a value from the following function: inline double f (double x) { return ( tanh( 3*(5-x) ) *0.5 + 0.5); } Profiling indicates that this part of the program is where most of the time is spent. Since the program will run for weeks if not months, I would like to optimize this operation and am considering the use of a lookup table. I know that the efficiency of a lookup table depends on the size of the table itself, and on the way it's designed. Currently I

How to compute the height profile of a Tetris stack most efficiently?

两盒软妹~` 提交于 2019-12-24 17:18:22
问题 Problem Statement We're given an array of Integers stack of length height . The width tells us that at most the width -lowest bits in each entry of xs are set. Compute an array profile of length width such that profile[i] == max_i with: max_i is maximal with stack[max_i] having the i -th bit set. How can I achieve this in a more efficient way than below? Current solution Currently I go over the columns and check each bit separately. The following shows my current implementation in Scala. But