Questions tagged [coding-efficiency]

0

votes
0

answer
10

Views

Subset-AVG - Finding a subset of List Which Matches Known Rational Number

I've asked this on math overflow and used comments to clarify/overstate my question. I hope it has the intended effect and doesn't come off as jarring. I'm attempting to find what subset of numbers reach a known average. I have a list of known values, negative and possible decimals. They look somet...
Raymond Johnson
1

votes
0

answer
38

Views

Random down-sampling of a big file

I have a very big textual file (~500MB) containing ~100M rows. What I want to accomplish is to randomly sample (approximately) 5M rows out of the file as fast as possible, into a new file. The result is flexible - is has to be a 'good enough' randomness, and not a perfect one, and the number of samp...
ShaharA
1

votes
1

answer
53

Views

Most efficient way of animating hundreds of gameobjects with blender shape keys

I have my trees edited by shape keys in blender, now I want to trigger this wind animation in unity. I used animator and controller for this, but now I found out that there are blendshapes and I could use loop to change blendshape key value. There will be more than hundreds of trees, and i think to...
Darthy
1

votes
1

answer
202

Views

scipy.linalg.block_diag vs scipy.sparse.block_diag in terms of efficiency

I have a question about the way scipy builds block diagonal matrices. I was expecting that creating a sparse block diagonal matrix would be much quicker and more efficient than creating a dense one (because of sparsity compressions). But it turns out that it's not the case (or maybe am I using some...
mhaddad
1

votes
0

answer
859

Views

Why do we need Application.PathSeparator?

MS Office VBA has a property called Application.PathSeparator. I'm supportive of interoperability, but Office runs only on Windows & MacOS, and both platforms use the same \ path separator. When would it ever be advisable to use Application.PathSeparator (as opposed to simply hardcoding the \ and sa...
ashleedawg
1

votes
0

answer
58

Views

Efficient operation on block-diagonal matrices in MATLAB

I am looking for an efficient implementation of the following operation in MATLAB. Assume that there is A = blkdiag(A_1,...,A_i,...,A_n) and B = blkdiag(B_1,...,B_i,...,B_n). Assume there is some function of two blocks f(A_i,B_i) and output variable F = blkdiag(f(A_1,B_1),...,f(A_i,B_i),...,f(A_n,B_...
1

votes
0

answer
28

Views

Mimimum range in PRNG

I was trying to implement some PRNG algorithms in C# (like LCG, Lagged Fibonacci and so on), but I'm not sure about the implementation of a range-constrainted generation. While I understood that the module at the end of the equation is used to limitate to the maximum, I've found no way other than ju...
MDM-P
1

votes
2

answer
43

Views

Efficiently deleting rows with character variables in R

I would like to delete a few rows that have a specific character variable. I can do it but it is not efficient. The below code works but I would like a more efficient way. Stuff2
Jessi
1

votes
2

answer
116

Views

Big-O notation runtime: Cracking the Coding Interview example

I mainly just want to confirm my understanding. The following a big-o notation problem from Cracking the Coding Interview. The answer key says runtime is 'O(b) or O(n). The recursive code iterates through b calls, since it subtracts one at each level.' So I understand that the part of the function...
Jigar Patel
1

votes
1

answer
57

Views

How to increase efficiency

I have the following homework question: Suppose you are given two sequences S1 and S2 of n elements, possibly containing duplicates, on which a total order relation is defined. Describe an efficient algorithm for determining if S1 and S2 contain the same set of elements. Analyze the running time of...
user9589242
1

votes
4

answer
61

Views

How to return ratings based on given values

I need a method that returns a rating value based on the given argument. The Ratings class stores the upper and lower limits for a rating as integers (read from a xml file). Until now I have a method similar to the code below, but I am looking for a 'smarter' and more efficient way to get my rating....
Quen
-1

votes
0

answer
10

Views

Emacs & Multiple Monitors

This is my first post. I have just started a degree in computer science, but have been interested in programming for a while. I hope my time spent here will be illuminating. I have a quick question about using Emacs with multiple monitors. I try and live in Emacs as much as possible, which means tha...
wds
1

votes
1

answer
269

Views

Scala efficiency [closed]

I am interested on your views on Scala efficiency. It seems that Scala (and other functional programming languages) trade efficiency for code writing efficiency. The program below contains a test of a Scala program that contains an insertion sort in the style of both a pure functional approach and...
user2302244
1

votes
1

answer
33

Views

XML Design - Performance and Efficiency

I am making an XML map file for categories. I was wondering what the right approach would be considering the two options i have in mind. My main issue is speed/efficiency of the php code that may have to read the XML file. So here is my first approach Longsleeve Tops Shortsleeve Tops Short Gowns Eve...
jcobhams
1

votes
1

answer
90

Views

How can I improve the performance of the below python code

I wrote this piece of code shown below. I am having severe performance issues with it. Especially the loop where i loop 50 million times(for z in range(total):) seems very slow. Could I modify it to be a bit more efficient? - Maybe modify how it is storing sum of last 10 values in r1,r2? import nump...
anuragsodhi
1

votes
1

answer
352

Views

Dynamically Parsing JSON with Groovy

I have a JSON document pulled back from a support system API. With my code, I want to pull out the pre-configured fields dynamically, presuming that the JSON may have more or fewer of the desired fields when my program calls the API. I have some code that works, though it seems very convoluted and i...
Donglecow
1

votes
1

answer
68

Views

Making this LESS Mixin more efficient and less redundant?

so for a website project I had to create a LESS Mixin which I had never done before. I have the feeling that it is not as efficient as it could be and may be a little redundant. I looked through it but couldnt think of a better way to do it. Maybe you can give me some advice? Dont get me wrong, its...
SVARTBERG
1

votes
4

answer
75

Views

Does every simple mathematical operation use the same amount of power (as in, battery power)?

Recently I have been revising some of my old python codes, which are essentially loops of algebra, in order to have them execute faster, generally by eliminating some un-necessary operations. Often, changing the value of an entry in a list from 0 (as a python float, which I believe is a double by de...
iammax
1

votes
1

answer
36

Views

Efficiency difference between 2 linear line search in Python

I have a question regarding the difference in efficiency when doing list search. Why is there a difference between these two? test_list= [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50] The first one - def linearSearch(A,x): if x in A: return True return False The second one...
th_so
1

votes
1

answer
63

Views

How to compress primitive integer data for an array?

I am teaching myself java using the cs106a course from Stanford. Currently I am on chapter 10 of the book 'The Art and Science of Java'. The problem is to write a 3x3 Magic Square. The exercise: You have to write a 3x3 array Each side of the array(Magic Square) has to equal 15 The problem: The prog...
Pav
1

votes
2

answer
221

Views

How to efficiently calculate distance between GPS points in one dataset and GPS points in another data set using data.table

I am facing a coding (optimization) problem in R. I have a long data set with GPS coordinates (lon, lat, timestamp) and for every row I need to check whether the location is near a bus stop. I have a .csv file with all the bus stops (in the Netherlands). The GPS coordinates file is millions of entri...
L Smeets
1

votes
4

answer
0

Views

Is there any way to make the execution faster in the below Java code?

My Java code is as below. boolean almostIncreasingSequence(int[] sequence) { Integer[] arr = new Integer[sequence.length]; for(int ctr = 0; ctr < sequence.length; ctr++) { arr[ctr] = Integer.valueOf(sequence[ctr]); // returns Integer value } System.out.println('Integer :: ' + arr); List al = new Arr...
Virus
1

votes
1

answer
47

Views

Efficient coding in Netlogo, many procedures or few?

In terms of increasing the performance on a model in NetLogo is it better to code with as many procedures as possible or as few for example... (apologies for the very crude example, new to coding) I ask this because when coding quite complex procedures with many commands it 'looks' alot neater codi...
H.Tan
1

votes
1

answer
31

Views

Is sequential or random comparison more efficient?

I am wondering (purely out of curiosity) if it is more efficient to compare numbers sequentially or randomly. I initially thought that it would be more efficient to compare numbers sequentially, but I was not sure and I have know idea how I would go about figuring this out, so I figured that I would...
zoecarver
-2

votes
1

answer
17

Views

Finding the threshold value in a given array

Given a array, I have to find the maximum threshold value such that elements smaller than that in the array are multiplied by c1 and greater than that are multiplied c2. Now the sum I get by adding all in the elements of the array should cross the value given by the user. I thought of using a BST....
user10390214
-1

votes
2

answer
37

Views

How do I find a set of unique pairs of an array?

Suppose that I have the following array: array = [0, 1, 2, ... , n] How do I find a set such that the pairs in the set are all unique and non-repeated elements? This means that: • (x, y) = (y, x) so if (x, y) is in the set, then (y, x) would not be & vice-versa • If an element is already used, i...
Try Khov
1

votes
2

answer
331

Views

How can I make typing code more efficient?

I am a poor typist, I will admit. After my recent switch from a keyboard I had used for years to a slightly different one, a brief stint with Dvorak and not doing a great deal of typing for a while, I'm worse than normal! My latest tests show about 90 WPM for native language and about 50 for code. O...
user122072
-2

votes
0

answer
25

Views

BarTender project with C# - how do I improve efficiency and syntax?

as stated in the question I've got a working C# project. The project's goal is to open up the application BarTender and export printer code templates (a way of getting information from databases connected to BarTender). I would like to make improvements (i.e. syntax or build quality/speed). Any ge...
C. Catt
20

votes
2

answer
624

Views

Why does exponentiation (e.g., 10^6) take 4 times longer than calculator notation (e.g., 1e6) in R?

Using the scientific notation 10^6 in an R code (as I customarily do) results in a significantly longer computing time than using the calculator representation 1e6: > system.time(for (t in 1:1e7) x=10^6) utilisateur système écoulé 4.792 0.000 4.281 > system.time(for (t in...
Xi'an
2

votes
2

answer
233

Views

Better way in Python to count string in another string

This code works, but reading posts on here I get the impression it is probably not a very 'Pythonic' solution. Is there a better more efficient way to solve this specific problem: What this code does: it counts instances of one string found in another and return the count. It raises an error in ca...
TMWP
2

votes
1

answer
77

Views

Sparse matrix in matlab: set unrecorded elements to -1 instead of 0

I want to create a sparse matrix consisting mainly of -1, but also includes some 0 and 1. This is part of a larger project, so it is important that I do not switch -1 with 0. As default, sparse(A) in Matlab keeps track of only non-zero elements. Is there a way to keep track of only non-(minus one...
Matt T
3

votes
3

answer
103

Views

Is it faster to declare variables for loop criteria outside of the loop condition?

In the following scenario, is example 1 faster than example 2? Why? Example 1 int c = myArray.Count; for (int i = 0; i < c; i++) { Console.WriteLine(myArray[i]); } Example 2 for (int i = 0; i < myArray.Count; i++) { Console.WriteLine(myArray[i]); }
ryansin
0

votes
1

answer
23

Views

How to compact identical repeating Else If statements

I am experimenting with simple programs that the User can navigate with basic ReadLine input. At any given time during an input, there are a couple of commands that are always accessible regardless of the circumstances, here is an example: else if(input.ToLower() == 'exit' || input.ToLower() == 'lea...
Nathanial Lake
1

votes
3

answer
45

Views

How to efficiently make a numbered list in python Class-list

How to make the following code more compact and efficient. Here, the code was to find the position where certain numerical value resides in the list. For example, given set of number ListNo = [[100,2,5], [50,10], 4, 1, [6,6,500]] The value of 100, 50 and 500 was in the position of 0,3 and 9, respect...
1

votes
3

answer
64

Views

A tedious loop looking for improvements

in my code I need to calculate the values of a vector many times which are the mean values from different patches of another array. Here is an example of my code showing how I do it but I found that it is too less-efficient in running... import numpy as np vector_a = np.zeros(10) array_a = np.rando...
Lincheng Li
3

votes
2

answer
1.1k

Views

hasOwnProperty returns true, when checked against parent object properties

My JS code: console.clear(); function BaseClass(nname) { var name = nname; this.bc_PublicProperty = 'DefaultValue_BaseClass'; this.bc_getName = function GetName() { return name; }; this.bc_setName = function SetName(nname) { name = nname; }; } function SubClass(nname) { BaseClass.call(th...
Legends
1

votes
4

answer
95

Views

Python - My frequency function is inefficient

I'm writing a function that returns the number of times appeared of a word that appeared the most in the list of words. def max_frequency(words): '''Returns the number of times appeared of the word that appeared the most in a list of words.''' words_set = set(words) words_list = words word_dict = {}...
2

votes
4

answer
160

Views

How to simplify multiple repeated if/else if statements in C programming

I'm currently making a game that requires a lot if statements to figure out where the user clicks and to do things accordingly. It checks if the user clicks in the specified coordinates. The code below works perfectly fine, but I'm having trouble coming up with an efficient method to do this (not on...
KiranB
2

votes
6

answer
150

Views

R: efficiently computing summaries of value-subsets whose contents are determined by the relation between two variables

I have two tables, A and B. For each row of table A, I want to get some summary statistics for B$value where the value of B$location is within 100 of A$location. I've accomplished this using the for-loop below, but this is a slow solution that works well when the tables are small but I would like t...
Jautis
3

votes
0

answer
42

Views

Revolving Doors Riddle - Matlab Time-Efficient Sparse Matrix Use

I'm running a code with many iterations using large sparse matrices. There are three lines in my code that take about 75% of the running time and I think I can use the special structure of my sparse matrix to reduce that time, but so far I haven't managed to do it. I would love your help!! Ok, here...
Gidi

View additional questions