Tag Info

New answers tagged

6

Nearly all CPUs have a single instruction that will return the modulus of a value. For instance, consider this program: int main() { int i = 10; return i % 3; } If I compile this on my Intel OS X machine using g++ -S, the result will be some boilerplate and this: movl $3, %eax movl $0, -4(%rbp) movl $10, -8(%rbp) movl -8(%rbp), %ecx ...


1

I've been faced with this, and the answer is: For someone experienced in performance tuning, the new code can be tuned so almost no code can go faster. Here's an example. The reason is, there is a minimum length of time the task can take, and it's greater than one cycle. There are many, many programs that can do the task, and one or more of them take less ...


6

and don't want to ask the individuals doing the work to manually record things like how long it takes them to perform a given task Here's the problem. You basically want to create meaningful metrics, without measuring the only thing that matters. Nearly all of your users won't care about how fast the code itself is unless it causes a noticeable impact ...


3

Generally if you push more code to DB and if you do it right, it should result in performance increase. And I don't see why the interviewer claim its other way round. Personally I would not put any code into DB simply due to ease of maintenance and ease of unit testing. In most of the applications performance improvement due to moving logic into DB does not ...


2

The main reason for not having code in the database is testability and maintenance. It is relatively hard to test the database code and it is a kind of hidden logic, which will become hard to maintain as you logic is spread all over and regress especially in the maintenance phase of your project.


10

Performance does neither increase or decrease because "you put most of the code into database" or because "you keep the code out of the database". The key point is to put the right parts of the code into the database (or to keep them out). Parts which helps to reduce the network traffic might be a good fit for stored procedures. Parts which do heavy ...


3

This answer is specific to C++ (as indicated by the tag on this question). Most other compiled languages (outside C and C++) do not have such consideration, because in those languages there is no benefit in moving configurations to compile-time. Outside of C and C++, conditional compilation is greatly discouraged or simply unsupported. Also, C and C++ ...


1

The title hints that the topic is somewhat opinion-based. However, let's ignore this issue and address the question. I think the pros and cons are fairly obvious, since both methods are just trade offs. For example, let's say you've implemented a runtime configuration-system. Cons: What do you do if some values are missing in the config / the config ...


1

Your decision whether to have code-based configuration or file-based configuration will depend entirely on whether or not you need the flexibility of configuring at runtime vs. compile time. Performance is almost certainly a non-issue, since you can cache the values once they are read from the configuration file.


1

See http://stackoverflow.com/q/5527437/10396 for an implementation of a rolling median that uses a min-max heap to process each new sample in O(lgN). The heap keeps the data loosely sorted into two groups, one bigger than the median, one smaller. For each new sample, it swaps the the oldest item in the heap with the newest one. Rebalancing the heap takes ...


1

My suggestion would be to slurp the large list into a hash set, then use that to match items from the small list. A hash set is a structure that stores elements in an indexable memory structure, like an array, where the position of the element is equal to some hash value calculated using the object. That means that looking for a value in the hashset is a ...


2

Sort both lists with an efficient sorting algorithm (or ensure that the lists are "pre-sorted" by whoever/whatever created them). Then, if the first name in both lists is the same you've found a match, otherwise discard whichever name is "earlier"; and do that until one of the lists are empty. Some crude pseudo-code: do { status = ...


1

Sort the small list with an efficient sorting algorithm, traverse the big list and for every item in the big list use a binary search to find whether there's a matching item in the small list.


0

Finding things in one set that match those in another set and merging data is something that relational databases excel at. If this is something you need to do a lot, loading your lists into tables in your choice of SQL DB is probably your best option.


2

For certain types of data, you can achieve constant time median filtering (Perreault et al, 2007). That paper describes 2D median filtering on images, assuming the pixels are 8-bit integers. Note that "constant time" refers to constant time in the size of the window; it is not constant time in the size of data, or in the precision (bits) of data. As ...


2

Lets assume N=100. You have the raw values in chronological order raw[1],...,raw[100] and you have the ordered list of the same values as ordered[1],...,ordered[100]. What is the median? The median will be (ordered[50]+ordered[51])/2. Lets now move the window one position so raw data will be raw[2],...,raw[101]. How do you generate an updated list for ...


0

You can solve the problem of specialized methods by using Scala language. Scala can inline methods, this (in combination with easy higher order function usage) makes it possible to avoid code duplication for free — this looks like the main problem mentioned in your answer. But also, Scala has syntactic macros, which makes it possible to do a lot of things ...


4

If you need an overview of the benefits and best-practices on move semantics, please watch some of the conference recordings on the isocpp website. (At the bottom there's a link to older recordings.) Bjarne Stroustrup provide a prime motivating example on his website. http://www.stroustrup.com/C++11FAQ.html#rval Just consider the typical implementation ...


1

After several changes performance is perfectly acceptable now. There are a few things to always bear-in-mind for best performance when making a large number of changes to a worksheet: set calculations to manual (reset after) turn off screen updates (and back on after) if deleting data from a large number of rows, delete entire rows if you can - much ...


0

If you're talking about the difference between 2 ticks and 3 ticks, it could simply be that, for a given execution, you started counting ticks early or late in a single tick cycle, and that the execution times are actually identical. You should look into using timers with a higher precision than ticks; ticks are a very coarse measurement.


4

Is the cache always rendered useless after a context switch? No, not at all. Context switches are actually a concept of the software that runs on a CPU, not one of the CPU itself. When the software decides to do a context switch, the state of the CPU is saved somewhere convenient, a new or previously-saved state is loaded and execution jumps to the ...


1

This question probably doesn't belong to programmers but var request = function() { return new Promise(function(resolve, reject) { ... resolve(data); ... reject(err); } }; Is of course much slower than var request = promisify(function(callback) { ... callback(null, data); ... callback(err); }); However, ...


8

Bluebird author here. The accepted answer is wrong. V8 promises implementation is written in JavaScript not C. All JavaScript (including V8's own) is compiled to native code. Additionally user written JavaScript is optimized, if possible (and worth it), before compiled to native code. Promises implementation is something that would not benefit much or at ...


1

I'll discourage the option to use triggers in such case. You might be better off thinking in API terms to your model. As the comments point out, use stored procedures, as they will be easier to debug in case something goes not according to plan, keep in mind that you have a quite complex situation ;-) Some helpful references, wikipedia article about ...


4

Whether there is a performance penalty or not, would depend on whether your Java compiler is capable of in-lining / unrolling trivial lambda expressions like this one. In general, inlining in Java is limited by the presence of the final modifier, or when the compiler can deduce that the final keyword could have been used in the local context without ...



Top 50 recent answers are included