Skip to content

Instantly share code, notes, and snippets.

@ifraixedes
ifraixedes / nice-syntax-bad-performance.js
Last active August 29, 2015 14:03
It contains some cases where a nice syntax is used in expense of performance
'use strict';
var NUM_ITERATIONS = 99999999;
var i, tmp, tmp2, initTime, stopTime;
// Iteration using for loop assigning the value always
initTime = Date.now();
for (i = 0; i < NUM_ITERATIONS; i++) {
tmp = (i % 2) || tmp;
}
@ifraixedes
ifraixedes / performance-comparison-loop-array-with-for-and-array-methods-node.js
Last active August 29, 2015 14:03
Perfomance difference between looping an array using Array methods and simple boring for loop
'use strict';
var i, tmp, initTime, stopTime;
var arr = Array(99999999);
// Iterate using `for` loop
tmp = 0;
initTime = Date.now();
for (i = 0; i < arr.length; i++) {
tmp += i;
@ifraixedes
ifraixedes / app.js
Last active August 29, 2015 14:06
Executing Angular App from non-root URL, doing all the operations and loading the required route (external social networks login is one of the use cases)
angular.module('simplified', ['ng-route'])
.config([
'$routeProvider',
function ($router) {
$router.when('/', {
templateUrl: '/views/main.html',
controller: 'MainCtrl'
});
}
])
@ifraixedes
ifraixedes / json-lodash-clone.js
Created October 6, 2014 12:32
Execution diferential time between cloning with JSON and locash#cloneDeep
const _ = require('lodash');
const times = 1000000;
const srcObj = {
_string: 'hey you',
_array: [1, 2, 3, 4, 5, 6],
_obj: {
_string: 'hey you',
_array: [1, 2, 3, 4, 5, 6]
}
};
@ifraixedes
ifraixedes / function-bind-argument-prepending-performance.js
Created October 31, 2014 18:34
Function bind execution time with and without prepending a argurment
var title = "Sir,";
var obj = {
name: 'Ivan'
};
function getName(title) {
return title + " " + this.name;
}
// Iteration binded function without prepending any argument
@ifraixedes
ifraixedes / benchmark-metics.js
Last active August 29, 2015 14:15
Performance Execution on JS Objects Created in Different Ways
// Requires "npm install benchmark microtime"
/* helper functions */
function printSuiteResult(suiteResult, title) {
console.log("### " + title + " ###");
suiteResult.forEach(function (btest) {
var sep = "";
for (var s = 85 - btest.name.length; s > 0; s--) {
sep += " ";
@ifraixedes
ifraixedes / LICENSE
Last active August 29, 2015 14:17
Profiling Golang Slices of Structs vs Pointers to Structs
License
(The MIT License)
Copyright (c) 2015 Ivan Fraixedes (http://ivan.fraixed.es)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
@ifraixedes
ifraixedes / LICENSE
Last active May 6, 2018 06:44
AWS lambda handler which download images from S3, resizes them and upload the new ones to S3; tested with mocha, chai, sinon and proxyquire
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
(http://www.wtfpl.net/about/)
Copyright (C) 2015 Mario Mendes (@hyprstack)
Copyright (C) 2015 Ivan Fraixedes (https://ivan.fraixed.es)
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
@ifraixedes
ifraixedes / LICENSE
Last active August 13, 2021 14:51
Private properties on ES6 Classes using Proxies
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
(http://www.wtfpl.net/about/)
Copyright (C) 2015 Ivan Fraixedes (https://ivan.fraixed.es)
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ifraixedes
ifraixedes / benchmark_test.go
Created May 20, 2015 09:24
Benchmark Go Responses vs Standard Handler
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
(http://www.wtfpl.net/about/)
Copyright (C) 2015 Ivan Fraixedes (https://ivan.fraixed.es)
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.