Adding context to rewrite rules

In the following code, I want to rewrite g . f as h when possible. There may be cases h hasn't got the instance of class, but I'd like to do the rewrite when it's possible. I'm getting an error message suggesting this is achievable but I'm not sure e...
more »

2017-02-17 10:02 (1) Answers

Optimized way to cache a list of results?

This is a question for PHP/Laravel + Redis, but I'm sure it can be extrapolated to other languages/frameworks. I'm working on an app that displays a results (either from a user initiated search or category listing). By default, we paginate 30 resul...
more »

2017-02-16 22:02 (1) Answers

Iteration with creating a new DOM element

I have a problem on high load iteration. CommonMethods.showLoader(); var html = $("<div>"); for (var i = 0, length = folder.tracks.length; i < length; i++) { var clone = Track.create(folder.tracks[i], folder.folder_id); ...
more »

2017-02-13 13:02 (0) Answers

Server Response Time

I'm trying to decrease my server response time but can't understand why that doesn't drops. here's my website's result: https://gtmetrix.com/reports/www.mutlugunsusleri.com/gAZ9pUPc I used w3 total cache, maxcdn and optimized photos. but there's a ...
more »

2017-02-11 08:02 (0) Answers

A better 8x8 bytes matrix transpose with SSE?

I found this post that explains how to transpose an 8x8 bytes matrix with 24 operations, and a few scrolls later there's the code that implements the transpose. However, this method does not exploit the fact that we can block the 8x8 transpose into f...
more »

2017-02-10 15:02 (3) Answers

How 'smart' is GCC's Tail-Call-Optimisation?

I just had a discussion where the following two peices of C code were being discussed: For-Loop: #include <stdio.h> #define n (196607) int main() { long loop; int count=0; for (loop=0;loop<n;loop++) { count++; } printf("Resu...
more »

2017-02-10 13:02 (1) Answers

how does redundant if-else help to optimize?

I am reading the source code of Python's numpy library, and found the following snippets. It seems to perform element-wise operations on vectors (numpy.ndarray). For example, numpy.multiply([1,2,3],[4,5,6]) will get the result [4,10,18] #define BASE...
more »

2017-02-09 08:02 (2) Answers

optimize.root with a matrix equation

I am trying to solve the following linear system using optimize.root AX = b With the following code. A = [[0,1,0],[2,1,0],[1,4,1]] def foo(X): b = np.matrix([2,1,1]) out = np.dot(A,X) - b return out.tolist() sol = scipy.optimize.root(f...
more »

2017-02-06 03:02 (1) Answers

Optimizing sqrt(n) - sqrt(n-1)

Here is function that I call many times per second: static inline double calculate_scale(double n) { //n may be int or double return sqrt(n) - sqrt(n-1); } Called in loop like: for(double i = 0; i < x; i++) { double scale = calculate_s...
more »

2017-02-01 19:02 (3) Answers

How can I optimize this mysql query? Script Posted

So I have this code below that I use to connect and execute commands to the mysql on the server and it is used for an authentication system for any .NET project. Now when I get around 150+ users online it will start to slow down the site and the mysq...
more »

2017-01-31 22:01 (1) Answers

How to break an array into blocks

I have an array that represents points in a cuboid. It is a one dimensional array, which uses the following indexing function to realise the 3 dimensions: int getCellIndex(int ix, int iy, int iz) { return ix + (iy * numCellsX) + (iz * numCellsX ...
more »

2017-01-27 04:01 (4) Answers

C - Recursive function for minimum gap in array

I'm trying to optimize a function that, given an array of N int, return the minimum difference between an element and the previous one. Obviously the function is just for array with a dimension >=2. For example, given the array {2,5,1}, function retu...
more »

2017-01-27 00:01 (3) Answers

Find subset with similar mean as full set

I have 50 lists, each one filled with 0s ans 1s. I know the overall proportion of 1s when you consider all the 50 lists pooled together. I want to find the 10 lists that pooled together best resemble the overall proportion of 1s. The function I want...
more »

2017-01-26 18:01 (1) Answers