Last active
December 30, 2020 22:38
-
-
Save olleharstedt/eaaf1dd40be541f84aa0f3954a0ea54a to your computer and use it in GitHub Desktop.
Clone benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Query { | |
constructor() { | |
this.select = ''; | |
this.from = ''; | |
this.where = ''; | |
} | |
} | |
for (let i = 0; i < 1000000; i++) { | |
const q = new Query(); | |
const q1 = {...q, select: '1'}; | |
const q2 = {...q1, from: 'table'}; | |
const q3 = {...q2, where: 'a = b'}; | |
} | |
/* | |
for (let i = 0; i < 1000000; i++) { | |
const q = new Query(); | |
q.select = '1'; | |
q.from = 'table'; | |
q.where = 'a = b'; | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type query = { | |
select: string; | |
from: string; | |
where: string; | |
} | |
type query_mut = { | |
mutable select: string; | |
mutable from: string; | |
mutable where: string; | |
} | |
let _ = | |
for i = 0 to 1000000 do | |
let q : query = {select = ""; from = ""; where = ""} in | |
let q1 = {q with select = "1"} in | |
let q2 = {q1 with from = "table"} in | |
let q3 = {q2 with where = "a = b"} in | |
() | |
done; | |
(* | |
for i = 0 to 1000000 do | |
let q : query_mut = {select = ""; from = ""; where = ""} in | |
q.select <- "1"; | |
q.from <- "table"; | |
q.where <- "a = b"; | |
() | |
done | |
*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class QueryBuilder | |
{ | |
public $select; | |
public $from; | |
public $where; | |
public function withSelect($sel) | |
{ | |
$that = clone $this; | |
$that->select = $sel; | |
return $that; | |
} | |
public function withFrom($from) | |
{ | |
$that = clone $this; | |
$that->from = $from; | |
return $that; | |
} | |
public function withWhere($where) | |
{ | |
$that = clone $this; | |
$that->where = $where; | |
return $that; | |
} | |
} | |
for ($i = 0; $i < 1000000; $i++) { | |
$q = (new QueryBuilder())->withSelect('1')->withFrom('table')->withWhere('a = b'); | |
unset($q); | |
} | |
/* | |
for ($i = 0; $i < 1000000; $i++) { | |
$q = new QueryBuilder(); | |
$q->select = '1'; | |
$q->from = 'table'; | |
$q->where = 'a = b'; | |
unset($q); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment