Which yields faster code?

The true answer to your question is: “depends on the platform and compiler settings”. Let us take the case of no optimizations. There are 3 cases. Case 1: Adding the variable 3 times. The instructions: MOV Y, 0 ; Set Y to zero. ADD Y, Y, X ; Add X to Y and place result … Read more

PHP: What’s the speed difference “template” vs “quote”? [duplicate]

Let’s find out: <?php ob_start(); $a = 0; $time1 = microtime(true); for ($i = 0; $i < 100000; $i++) { echo “<html><body>$a</body></html>”; } $time2 = microtime(true); for ($i = 0; $i < 100000; $i++) { ?> <html><body><?php echo $a; ?></body></html> <?php } $time3 = microtime(true); ob_end_clean(); echo ‘Just echo: ‘ . ($time2 – $time1) . … Read more

Convert JSON to array in Javascript

You could splice the values and get only the first two elements as number. var array = [{ time: “18:00:00” }, { time: “10:00:00″ }, { time:”16:30:00” }], result = array.map(o => o.time.split(‘:’).slice(0, 2).map(Number)); console.log(result); .as-console-wrapper { max-height: 100% !important; top: 0; } If you have JSON sting, then you need to parse it with … Read more