efficiency

determining the distance between points in n-dimensions

Hey, I am building a mySQL table listing points in n-dimensions, each dimension being indexed. Given any point in the n-dimensional system, I would like to be able to output all of the other points in order of their distance from the chosen point. A simple solution would be to calculate distances from each point using the pythagorean ...

two methods of composing functions, how different in efficiency?

Hi, Let f transform one value to another, then I'm writing a function that repeats the transformation n times. I have come up with two different ways: One is the obvious way that literally applies the function n times, so repeat(f, 4) means x → f(f(f(f(x)))) The other way is inspired from the fast method for powering, which means div...

Getting record differences between 2 nearly identical tables

I have a process that consolidates 40+ identically structured databases down to one consolidated database, the only difference being that the consolidated database adds a project_id field to each table. In order to be as efficient as possible, I'm try to only copy/update a record from the source databases to the consolidated database ...

Cost of list functions in Python

Based on this older thread, it looks like the cost of list functions in Python is: Random access: O(1) Insertion/deletion to front: O(n) Insertion/deletion to back: O(1) Can anyone confirm whether this is still true in Python 2.6/3.x? ...

Debugging and improving the efficiency C# winform code

Hello everyone. I have written a Winform application in C#. How can I check the performance of my code. By that I mean, how can I check which forms references are active at a given time or event, so that I can remove them if they are not required (make them available for garbage collection). Is there a way to do it using VS 2005 or any f...

R: how do I dichotomise efficiently

Is there a more "R-minded" way to dichotomise efficiently? Thanks. y<-c(0,3,2,1,0,0,2,5,0,1,0,0);b<-vector() for (k in 1:length(y)) { if (y[k] == 0) b[k] = 0 else b[k] = 1 } y;b ...

N-Way Intersection of Sorted Sequential Access Iterators

I want to iterate over the intersection of n sub-iterators. Each sub-iterator is sorted from GREATEST TO LEAST, and the values must be accessed sequentially. Assume no duplicate values. So far I have thought of two approaches using a heap/priority queue, but I'm struggling to figure out which is more efficient - it seems like it may b...

Python: Replace values in list

Hello Stack Overflow Community, I have a list where I want to replace values with None where condition() returns True. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] For example, if condition checks bool(item%2) should return: [None, 1, None, 3, None, 5, None, 7, None, 9, None] What is the most efficient way to do this? ...

My first F# program...

The idea was to create/populate a perfmon counter with the # of files in a directory. Apparently FileNet (a program) uses a given directory as a queue, and gets hung up sometimes. Hence the need to monitor the # of files that are stacking up... Now most of you will probably LOL your asses off at my spider web of "if/then" statements, ...

Efficient way to implement LinkedIn like "How you are connected to" feature?

So LinkedIn has this cool feature in which while visiting some user's profile, linkedin prompts how you are connecting to that user through the network. Assuming that the visitor and the profile owner are two nodes of a graph where the nodes represent users and edge represents friendship, a simple solution could be a bfs starting fr...

DateTime.AddDays or new DateTime

I'm creating a list of a month's worth of dates. I'm wondering what will be more efficient List<DateTime> GetDates(DateTime StartDay) { List<DateTime> dates = new List<DateTime>(); int TotalDays=StartDay.AddMonths(1).AddDays(-1).Day; for (int i=1; i<TotalDays; i++) { dates.Add(new DateTime(StartDay.Year, StartDay.Month, i)); ...

In a Property Setter is it Beneficial to only Set if Value Differs?

Hi All, I'm wondering what benefits this code has: private int _TestID; public int TestID { get { return _TestID; } set { if(_TestID != value) { _TestID = value; } } } vs. this: private int _TestID; ...

Performance of RSA based on keysize

Hi, A theoretical question not depending on implementation, how much of a decrease in performance is 1024bit vs 4096bit RSA? Thanks ...

Is putting a function within an if statement efficient? (C++)

I've seen statements like this if(SomeBoolReturningFunc()) { //do some stuff //do some more stuff } and am wondering if putting a function in an if statement is efficient, or if there are cases when it would be better to leave them separate, like this bool AwesomeResult = SomeBoolReturningFunc(); if(AwesomeResult) { //do ...

An efficient equals(Object o) implementation

I read this SO post after I wrote out the title but still decided to go through with the question on bug-proof implementations of equals in Java. This is my normal implementation @Override public boolean equals(Object o){ if(o == null) return false; if(o instanceof CompositePk == false) return false; ...

Java: Calculating a metric of String simliarity

This method is a bottleneck in my program. (Or, it is at least where most of the time is being spent.) Its purpose is to calculate the similarity between two strings based on the way characters occur in both, or occur in one or not the other. The code is correct, but I would like to optimize it. Do you see any inefficiencies, bad pract...

CSS reducing syntax

I'd like two different HTML elements that are at the same nesting level to have identical CSS property values. Is there an alternative to this wasteful syntax? .level1 .level2 .level3 element1 { /*rules*/ } .level1 .level2 .level3 element2 { /*rules*/ } I was thinking .level1 .level2 .level3 element1, .level1 .level2 .level3 element2...

Looking for a multidimensional optimization algorithm

Problem description There are different categories which contain an arbitrary amount of elements. There are three different attributes A, B and C. Each element does have an other distribution of these attributes. This distribution is expressed through a positive integer value. For example, element 1 has the attributes A: 42 B: 1337 C: ...

Is it fair to be held up to mockery for preferring to run "mvn clean install" as 2 commands ?

One of my team mates was held up for mockery by the team leads for preferring to run maven as: $ mvn clean $ mvn install The discussion by the team leaders was about efficiency and speed of work & someone brought up the issue that person X is continuing to split $ mvn clean install into 2 separate commands. I know, I know that lif...

SQL Archive Script

Hello, I'm trying to archive records from a table in a database to an identical table in an archive database. I need to be able to do an insert for all records with a date greater than three years ago, and then delete those rows. However, this table has millions of records which are live, so I want to run this in a loop of roughly 100 ...