In general, which is more expensive? A double-nested for loop and one call to a database or a call to a database for each of N items in only one for loop?
Not looking for an answer down to microseconds, just a general idea of which direction I should take.
TIA.
...
Sometimes it necessary to compary a string's length with a constant.
For example:
if ( line.length() > 2 )
{
// Do something...
}
But I trying to avoid using "magic" constants in code.
Usually I use such code:
if ( line.length() > strlen("[]") )
{
// Do something...
}
It more readable, but not efficient because of function ca...
is there a difference in the order of uniq and sort when calling them in a shell script? i’m talking here about time- and space-wise.
grep 'somePattern' | uniq | sort
vs.
grep 'somePattern' | sort | uniq
a quick test on a 140 k lines textfile showed a slight speed improvement (5.5 s vs 5.0 s) for the first method (get uniq values a...
I have a file which has a many random integers(around a million) each seperated by a white space. I need to find the top 10 most frequently occurring numbers in that file. What is the most efficient way of doing this in java?
I can think of
1. Create a hash map, key is the integer from the file and the value is the count. For every numb...
I need to write an application that fetches element name value (time-series data) pair from any xml source, be it file, web server, any other server. the application would consume the XML and take out values of interest, it has to be very very fast (lets say 50000 events/seconds or more) also the XML document size would be huge and frequ...
I am studying up for a pretty important interview tomorrow and there is one thing that I have a great deal of trouble with: Sorting algorithms and BigO efficiencies.
What number is important to know? The best, worst, or average efficiency?
...
What is generally faster:
if (num >= 10)
or:
if (!(num < 10))
...
I would like to get all elements following a particular index of a list. This could be written as:
set foo {0 1 2 3 4 5 6 <...> n}
puts [lrange $foo 1 [llength $foo]]
However, it seems like a waste to compute the length of the list. It would be nice if the last argument to lrange was optional and omitting it meant to continue until ...
I've noticed there are many PHP forum packages out there - http://en.wikipedia.org/wiki/Comparison%5Fof%5FInternet%5Fforum%5Fsoftware%5F%28PHP) . I specifically am looking for a forum package that scales well - from what I hear both Vbulletin and Simple Machines, two of the most popular forum packages, require substantially more horsepow...
I have a simple contest sign-up web form. Each contestant can check a box to be eligible to win one of 20 prizes. Upon submitting a form, a row is created in the "contestants" table. For each prize they have checked, a row in the "entries" table is created.
I am trying to make a "results" page that lists all prize names, and below each ...
I am going to write some image processing programs for Texas Instruments DaVinci platform. There are tools appropriate for programming in the C language, but I wonder if it is really possible to take full advantage of the DSP processor without resorting to an assembly language. Do you know about any comparisons of speed between programs ...
Let's say I have some code like the following, and that processData gets executed hundreds or even thousands of times per minute:
class DataProcessor {
private:
DataValidator* validator;
bool atLeastOneDataPoint;
bool dataIsValid(Data* dataToValidate) {
return validator->validate(dataToValidate);
}
public:
/...
UPDATE:
The final version of my utility looks like this:
StringBuilder b = new StringBuilder();
for(char c : inLetters.toLowerCase().toCharArray())
{
switch(c)
{
case '0': b.append("0"); break;
case '1': b.append("1"); break;
case '2': case 'a': cas...
I am continually pulling in a list (over 200) entries from a remote server and showing them in a table (many pieces of data per row). The data changes and fluctuates over time. What's the most efficient way in JS to render this to the screen. As the data changes do I simply wipe my DOM and re-render with the new data; do I have a list of...
I want to take the data from a BytesMessage and pass is to a class that will de-serialize it. I'm running some tests to see if using Hessan for serialization is any better than Java Serialization.
The Hessan classes take an InputStream to read from. The BytesMessage has no getInputStream() method so I thought I'd write a wrapper aroun...
I am representing a grid with a 2D list in python. I would like to pick a point (x,y) in the list and determine it's location...right edge, top left corner, somewhere in the middle...
Currently I am checking like so:
# left column, not a corner
if x == 0 and y != 0 and y != self.dim_y - 1:
pass
...
Hey,
I'm interested in what is the more efficient way of handling user data in my game. When someone is playing the game, data from the server will constantly need to be queried from the database.
So I want to know if it is more efficient to keep querying the database or to store the data from the first query in a session and then keep...
I don't know how about you, but I'm not very fond of the way arrays are constructed in PHP. I have this feeling that I use array keyword way too often and that array($k => $v) or e.g. array($k1=>array($k2=>$v)) are way too long given usefulness of maps.
(Moreover, recently I've learned JS way of doing it and now I really am jealous)
The...
Or is it just a personal preference thing? What I'm getting at is, is there a specific benefit to using either method?
<link href="main.css" rel="stylesheet" type="text/css">
versus
<style type="text/css">
@import url('main.css');
</style>
...
I was wondering if it would be more efficient to use document.getElementById() n number of times or to use document.getElementsByTagName() and loop through the result looking for the specific Element ids?
...