Dictionary vs Object – which is more efficient and why?

Have you tried using __slots__? From the documentation: By default, instances of both old and new-style classes have a dictionary for attribute storage. This wastes space for objects having very few instance variables. The space consumption can become acute when creating large numbers of instances. The default can be overridden by defining __slots__ in a … Read more

Why is require_once so bad to use?

This thread makes me cringe, because there’s already been a “solution posted”, and it’s, for all intents and purposes, wrong. Let’s enumerate: Defines are really expensive in PHP. You can look it up or test it yourself, but the only efficient way of defining a global constant in PHP is via an extension. (Class constants … Read more

Debug vs. Release performance

Partially true. In debug mode, the compiler emits debug symbols for all variables and compiles the code as is. In release mode, some optimizations are included: unused variables do not get compiled at all some loop variables are taken out of the loop by the compiler if they are proven to be invariants code written … Read more

Why is arr = [] faster than arr = new Array?

Further expanding on previous answers… From a general compilers perspective and disregarding VM-specific optimizations: First, we go through the lexical analysis phase where we tokenize the code. By way of example, the following tokens may be produced: []: ARRAY_INIT [1]: ARRAY_INIT (NUMBER) [1, foo]: ARRAY_INIT (NUMBER, IDENTIFIER) new Array: NEW, IDENTIFIER new Array(): NEW, IDENTIFIER, … Read more

How slow are .NET exceptions?

I’m on the “not slow” side – or more precisely “not slow enough to make it worth avoiding them in normal use”. I’ve written two short articles about this. There are criticisms of the benchmark aspect, which are mostly down to “in real life there’d be more stack to go through, so you’d blow the … Read more

How much is the overhead of smart pointers compared to normal pointers in C++?

std::unique_ptr has memory overhead only if you provide it with some non-trivial deleter. std::shared_ptr always has memory overhead for reference counter, though it is very small. std::unique_ptr has time overhead only during constructor (if it has to copy the provided deleter and/or null-initialize the pointer) and during destructor (to destroy the owned object). std::shared_ptr has … Read more

How do I get Windows to go as fast as Linux for compiling C++?

Unless a hardcore Windows systems hacker comes along, you’re not going to get more than partisan comments (which I won’t do) and speculation (which is what I’m going to try). File system – You should try the same operations (including the dir) on the same filesystem. I came across this which benchmarks a few filesystems … Read more