efficiency

which of the two practices is more efficient in Java?

I have an object array, I know that the elements are type String, say I need to access them many times. Practice 1: access the element by array index and cast it to String every time I need it. Practice 2: create local String instances and access each of the elements once. Which will run faster? If it's on a mobile device where memor...

Rails efficient way to save non-duplicates?

I have a type I want to save to the database, say, email addresses, and I want to save them in the most efficient way possible. I also want to associate posts with email addresses, so if it exists, I want to assign the post to that email address. Should I do a search first and then go based on that result, or is there a more efficient wa...

efficiency of multiple canvas size increases in silverlight

Hi, I'm writing a silverlight app which does some real-time charting. Basically, I just have some polylines overlaid on a canvas. The user can record data for arbitrary amounts of time, and so the width of the canvas is increasing as necessary. Since the canvas is wrapped inside a scrollviewer, it can get quite large. Haven't seen a...

Skip to end of time quanta

Is it possible to skip to the end of a process's allocated time-quantum? I have a program that works in parallel on a piece of shared memory, and then all of the processes need to wait for the others to finish and sync up before the next step. Each process will do a maximum of one iteration more than any other, so any timing difference...

Logical vs Numerical array in MATLAB

I am comparing two binary arrays. I have an array where values can either be one or zero, one if the values are the same and zero if they are not. Please note I am doing other stuff beyond checking, so we don't need to get into vectorization or the nature of the code. What is more efficient, using a numerical array or a logical array in...

How to effeciently spread objects on a 2D surface in a "natural" way?

Hello all, i would like to effeciently generate positions for objects on a given surface. As you probably guessed this is for a game. The surface is actually a 3D terrain, but the third dimension does not matter as it is determined by terrain height. The problem is i would like to do this in the most effecient and easy way, but still g...

Efficient memory reallocation question

Let's say I have a program(C++, for example) that allocates multiple objects, never bigger than a given size(let's call it MAX_OBJECT_SIZE). I also have a region(I'll call it a "page") on the heap(allocated with, say, malloc(REGION_SIZE), where REGION_SIZE >= MAX_OBJECT_SIZE). I keep reserving space in that page until the filled space e...

BitSet memory usage in Scala

I would like to know what is the memory usage of BitSet in Scala.For example, if I do: var bitArray:BitSet=new BitSet(10) bitArray.add(0) bitArray.add(2) bitArray.add(4) bitArray.add(6) bitArray.add(8) How does that compare with and array containing the even numbers 0,2,4,6,8? What about writing a number in binary: var...

Software usability vs efficiency

Does ensuring software usability always result in a decrease in efficiency? ...

Is it inefficient to specify default rules to CSS?

As an example, imagine I have a table. The standard alignment behaviour (not sure if this is html specification or just the browsers I use?) seems to be to left align the body elements and center align the head elements. So if I wanted everything left aligned, is it less efficient to write #MyTable td { text-align: left; } than t...

Performance Hit using CAST() in TSQL (SQL Server)?

We have a SQL generator that emits SQL conditional statements generically for specified fields (which for the sake of discussion: we will label as myField). So, if myField is of type NVARCHAR, we can do a comparison of said field against a string like so: myField = 'foo'. However, this does not work for fields of type NTEXT. Thus, w...

MySQL: Efficiently finding rows where the contents of a column is the beginning of a string

I have a MySQL table in which a column contains string prefixes. For instance these prefixes could be top-level directories on an Unix file system: my_table: +---------+ | prefix | +---------+ | /usr/ | | /bin/ | | /var/ | | /lib/ | +---------+ How can I write a query that efficiently finds all rows in this table where th...

MySql Join a View Table as a Boolean

I have a users table, and a view table which lists some user ids... They look something like this: Users: User_ID | Name | Age | ... 555 John Doe 35 556 Jane Doe 24 557 John Smith 18 View_Table User_ID 555 557 Now, when I do run a query to retrieve a user: SELECT User...

Most Effective Public Key Encryption Method

There seems to be a lot of hype about asymmetric Public Key encryption. RSA, PGP... etc. You have a set of two keys and distribute one, so that either only you can encrypt the message or only you can decrypt the message. One method provides a way to verify the sender, while the other provides a way to secure the message. (Feel free to co...

database performance

Say there is a website with 100,000 users each has up to 1000 unique strings attached to them so that there are maximum 100,000,000 strings in total. Would it be better to have 1 table with each string being one record along with it's owner's id. So that you end up with 1 table with 100,000,000 records with 2 fields (text and user id). ...

Compiling in constants at runtime

I have a program for some scientific simulation stuff, and as such needs to run quickly. When I started out, I was somewhat lazy, and decided to allow inputting constants later; and just used #define macros for them all. The problem is that when I tried changing that, it got a lot slower. For example, changing #define WIDTH 8 //.......

Efficient exception handling techniques

I am writing an application in C# that requires me to create an Array object on the fly from some dimensions the user passes in. The Array.CreateInstance() method can throw (by last count) 6 different exceptions that I would want to handle. For each exception I would want to inform the user by a simple MessageBox.Show() and a message tai...

Efficient algorithm to find String overlaps.

I won't go into the details of the problem I'm trying to solve, but it deals with a large string and involves finding overlapping intervals that exist in the string. I can only use one of the intervals that overlap, so I wanted to separate these intervals out and analyze them individually. I was wondering what algorithm to use to do this...

Many-to-many relationships in Google AppEngine - efficient?

Hi, I'm using Google Appengine to store a list of favorites, linking a Facebook UserID to one or more IDs from Bing. I need function calls returning the number of users who have favorited an item, and the number of times an item has been favorited (and by whom). My question is, should I resolve this relationship into two tables for eff...

Django - Keeping save() based transactions short

As django model save() methods are not lazy, and as keeping transactions short is a general good practice, should saves be preferably deferred to the end of transaction blocks? As an example, would the code sample B hold a transaction open for less time than code sample A below? Code sample A: from django.db import transaction from my...