What’s the best way to convert a number to a string in JavaScript?

like this: var foo = 45; var bar=”” + foo; Actually, even though I typically do it like this for simple convenience, over 1,000s of iterations it appears for raw speed there is an advantage for .toString() See Performance tests here (not by me, but found when I went to write my own): http://jsben.ch/#/ghQYR Fastest … Read more

Which Python memory profiler is recommended? [closed]

My module memory_profiler is capable of printing a line-by-line report of memory usage and works on Unix and Windows (needs psutil on this last one). Output is not very detailed but the goal is to give you an overview of where the code is consuming more memory, not an exhaustive analysis on allocated objects. After … Read more

Why shouldn’t I use PyPy over CPython if PyPy is 6.3 times faster?

NOTE: PyPy is more mature and better supported now than it was in 2013, when this question was asked. Avoid drawing conclusions from out-of-date information. PyPy, as others have been quick to mention, has tenuous support for C extensions. It has support, but typically at slower-than-Python speeds and it’s iffy at best. Hence a lot … Read more

Why is [] faster than list()?

Because [] and {} are literal syntax. Python can create bytecode just to create the list or dictionary objects: >>> import dis >>> dis.dis(compile(‘[]’, ”, ‘eval’)) 1 0 BUILD_LIST 0 3 RETURN_VALUE >>> dis.dis(compile(‘{}’, ”, ‘eval’)) 1 0 BUILD_MAP 0 3 RETURN_VALUE list() and dict() are separate objects. Their names need to be resolved, the … Read more

Why is my program slow when looping over exactly 8192 elements?

The difference is caused by the same super-alignment issue from the following related questions: Why is transposing a matrix of 512×512 much slower than transposing a matrix of 513×513? Matrix multiplication: Small difference in matrix size, large difference in timings But that’s only because there’s one other problem with the code. Starting from the original … Read more

What is a “cache-friendly” code?

Preliminaries On modern computers, only the lowest level memory structures (the registers) can move data around in single clock cycles. However, registers are very expensive and most computer cores have less than a few dozen registers. At the other end of the memory spectrum (DRAM), the memory is very cheap (i.e. literally millions of times … Read more

How to create a new object instance from a Type

The Activator class within the root System namespace is pretty powerful. There are a lot of overloads for passing parameters to the constructor and such. Check out the documentation at: http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx or (new path) https://docs.microsoft.com/en-us/dotnet/api/system.activator.createinstance Here are some simple examples: ObjectType instance = (ObjectType)Activator.CreateInstance(objectType); ObjectType instance = (ObjectType)Activator.CreateInstance(“MyAssembly”,”MyNamespace.ObjectType”);

MyISAM versus InnoDB [closed]

I have briefly discussed this question in a table so you can conclude whether to go with InnoDB or MyISAM. Here is a small overview of which db storage engine you should use in which situation: MyISAM InnoDB —————————————————————- Required full-text search Yes 5.6.4 —————————————————————- Require transactions Yes —————————————————————- Frequent select queries Yes —————————————————————- Frequent … Read more