At scale, is there a significant performance loss by wrapping ruby 'base text' in <rb> tags (ie: text node vs. element)?

Is there a significant difference between the efficiency of these two structures at large-scale (eg. wrapping each word in the Chinese-language Second World War Wikipedia article – which contains thousands of text-containing nodes – with ruby ann...
more »

Speeding up / Optimising this code in C/Java/anything

So I have two matrices with total 2N elements. So, each one has length of 1xN. What I want to do is to exchange their elements so that one of the matrices has the smallest elements, while the other matrix has the largest of the elements. The followi...
more »

Gradient descent optimization for multivariate scalar functions

I attempted to test my gradient descent program on rosenbrock function. But no matter how I adjusted my learning rate (step argument), precision (precision argument) and number of iterations (iteration argument), I couldn't get a very close result. ...
more »

ES6 Tail Recursion Optimisation Stack Overflow

Having read Dr Rauschmayer's description of recursive tail call optimisation in es6, I've since been trying to recreate the 'zero-stack' execution of the recursive factorial function he details. Using the Chrome debugger to step between stack frames,...
more »

Optimize Case Statement

We have a method for writing command data to a device. The method first converts the data to the form accepted by the device and then writes the data to the serial port. The data conversion is done with a case statement as given below. For 10 command...
more »

Caching a list of links which appears on every page

I have a list of the last 5 article titles and links to them at the footer of my website, that is, it's shown on every page. I'm thinking about optimization that by caching that list because a list of articles changes at most once in day or a few day...
more »

Python scipy optimization does not find minimum

Trying to use scipy.optimize.minimize, it seems like the optimization fails. I did the following: 1. The objective function is: f(x)= x[0]+x[1]+x[2]+x[3]+10 2. The constraint is: x_i >= 0 3. The initial guess is: x0 = [1,1,1,1] Very trivial proble...
more »

Why is this code slower when the array size is even?

Warning: Actually it is not due to power of 2 but parity. See the EDIT section. I have found a code which shows quite a strange behaviour. The code uses a 2D array (size x size). When size is a power of 2, the code goes between 10% and 40% slowe...
more »

Apply function between subsequent rows in more efficient way with Pandas

I have a dataframe df that is defined like so: import numpy as np import pandas as pd dic = {'A':['1A','1A','3C','3C','3C','7M','7M','7M'],'B':[10,15,49,75,35,33,45,65],'C':[11,56,32,78,45,89,15,14],'D':[111,0,np.nan,np.nan,np.nan,np.nan,np.nan,np.n...
more »

Speed up the lookup procedure

I have two tables: coc_data and DT. coc_data table contains co-occurrence frequency between pair of words. Its structure is similar to: word1 word2 freq 1 A B 1 2 A C 2 3 A D 3 4 A E 2 Second tabl...
more »

In Javascript (V8) why does forEach on an array consume much more memory than a simple for loop?

I'm performing some simple data validation on a large set of data in Node.js (version v7.5.0, with a matrix of 15849x12771 entries). The entire data set is in memory for now, for performance reasons. Therefore it is critical for me to reduce the amou...
more »

Scipy optimisation: Get the function to print out its iterations

I am using scipy.optimize.minimize()to minimise a certain function. I want to compare the performance of different methods, BFGSand L-BFGS-B, and for that, I would like the function to print out its values and error margins as it is optimising. The...
more »

How to make this Oracle select statement perform faster?

Could any please advise on how to make this query perform faster than it is at the moment? T2.ADI is indexed on TABLE2 T1.ADI is indexed on TABLE1 T1.RC AND T1.BEG_DT_TM is composite indexed on TABLE1 Is there anything else I could do to make i...
more »

C - how would compiler optimization affect a for loop with no body?

I have some legacy code where a timewasting loop has been included to allow time for an eeprom read to complete (bad practice): for(i = 0; i < 50; i++); However, peculiar things happen when compiler optimizations are switched on for speed. It ...
more »

constrOptim always returns starting values as optima, counts = 0, iterations = 1

Something funny is going on with my constrained optimization, but I'm not sure what the problem is. The "optimized" values are always identically equal to my starting values. It says it's converged, but counts = 0 and iterations = 1. I'm not sure why...
more »

Can the JVM JIT specialize non-overridden methods in sub-classes?

Well, that title along can't get the idea across but basically what I mean is that given some method m() in a class Base, which is not overridden in some subclass Derived, are the JIT compilers in current JVMs1 capable of "specializing"0 m() anyway w...
more »

Non-Linear Minimization (nlm) in R with error: incorrect number of dimensions

I have this code where it calculates the negative binomial distribution, with parameters: ce <- c(0, 1, 2, 3, 4, 5) ce <- as.integer(ce) comp <- c(257, 155, 64, 17, 5, 2) comp <- as.integer(comp) data.cells <- data.frame(ce, comp) p...
more »

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 »

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 »

Keeping the potential for inlining when there are some recursive cases

Consider the following data type, which is only intended to be illistrative: data D where D1 :: Int -> D D2 :: String -> D DJ :: D -> D -> D And perhaps a function on it, say toString: {-# INLINE toString #-} toString x = case x...
more »

What do you call the property of a list that describes the degree to which it contains duplicates?

I have a function that selects Cartesian products of lists such that the number of duplicate elements is highest: import Data.List (nub) f :: Eq a => [[a]] -> [[a]] f xss = filter ((==) minLength . length . nub) cartProd where minLength...
more »

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 »

How to replace this slow filtering function using a faster pandas-only approach?

Here's what I'd like to do: On this DF: df = pd.DataFrame(columns=['Entry', 'Exit'], data=np.array([[257, 259], [259, 260], [270, 271], [271, 273], [272, 274], [305, 305], [317, 320], [323, 326], [324, 326], [325, 328], ...
more »

How to set integer constraint using "fnmap" in DEoptim (R)

I am using DEoptim in R in order to maximize a likelihood function for the bivariate student t distribution. This distribution requires that the degrees of freedom be integer (I can already set the positive contrain using the lower and upperbound in...
more »

Why this program seems not to be fusing properly?

I was under suspect that a given program wasn't fusing as it would and made this test to confirm: module Main where import qualified Data.Vector.Unboxed as V main :: IO () main = do let size = 100000000 :: Int let array = V.replicate size 0 :...
more »

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 »

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 »

Why is a simple loop optimized when the limit is 959 but not 960?

Consider this simple loop: float f(float x[]) { float p = 1.0; for (int i = 0; i < 959; i++) p += 1; return p; } If you compile with gcc 7 (snapshot) or clang (trunk) with -march=core-avx2 -Ofast you get something very similar to. ....
more »

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 »

Why is declaring an array using so much CPU, and how can I optimize it?

I am writing a chess engine as a learning project. To decide what move to make, it needs to analyze all board states that can be reached by making 4 moves from the current board state. That means I have to analyze hundreds of thousands of boards. Th...
more »

Using a Swift tokeniser library, is it more efficient to tokenise one HTML node at a time, or whole tree at once?

I'm making an iOS app in Swift 3 and using its CFStringTokenizer library for tokenisation. I've built a simple web browser and want to tokenise all the Chinese words in a webpage (via Swift), then visually separate them (by injecting Javascript into ...
more »

I'm using itertools.combinations() as follows: import itertools import numpy as np L = [1,2,3,4,5] N = 3 output = np.array([a for a in itertools.combinations(L,N)]).T Which yields me the output I need: array([[1, 1, 1, 1, 1, 1, 2, 2, 2, 3], ...
more »

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 »

Why/When you would not want to have Java 8 UseStringDeduplication enabled in JVM?

Java 8 introduced String Deduplication that can be enabled by launching JVM with -XX:+UseStringDeduplication option allowing to save some memory by referencing similar String objects instead of keeping duplicates. Of course it's effectiveness varies ...
more »