Tag Info

Hot answers tagged

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 ...


8

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 ...


7

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 ...


6

Java streams do not iterate through your collection once for each statement, despite what the syntax implies. It applies the entire chain to each element, one element at a time. In your case, the stream would operate exactly like the loop. Take an element, check it against your predicate, and then apply your operation, then move on to the next element.


4

The challenge is how should this information be stored efficiently in an RDBMS? The question should be why should this information be stored in a RDBMS at all? What are you going to do with it once it's there? If all you're going to do is "save" a spreadsheet into the database and then pull it back out again, then I'd suggest you're wasting your ...


4

Iterating through a List is (slightly) slower than a plain array due to a few factors: Bounds checks: This is likely to be the biggest factor; every single indexer access to the List is going to do a bounds check. Bounds checking on a raw array can often be trivially optimized out of a loop by the JIT. Method call costs: The indexer on a List is a method ...


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 ...


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++ ...


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

Yes, the big question is what do you want to do with these excel documents once they're in the DB. You can store them as BLOBS quite happily, but then you can store them as files on the filesystem too, and the latter allows you to manipulate the documents in various ways (eg running code to change them). If you're just storing them for later retrieval, ...


2

Modern CPUs don't do one instruction at a time. Instead, they might be decoding one group of instructions while an earlier group are waiting for dependencies and waiting to be sent to execution units, while even earlier instructions are being executed, while even earlier instructions are being retired (committed to state). It's (literally) a pipeline of ...


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 ...


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 = ...


2

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.


2

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 ...


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.


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

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 ...


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

This question is too broad; there are too many factors that could contribute to the fluctuations in the time taken to execute some source code. The poorly-written question also doesn't help - it is unclear whether the asker is more interested in knowing the possible factors that affect nanoscopic performance (on the order of 1 - 10 CPU instructions) or ...


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 ...



Only top voted, non community-wiki answers of a minimum length are eligible