Skip to content

Instantly share code, notes, and snippets.

View mcuadros's full-sized avatar

Máximo Cuadros mcuadros

View GitHub Profile
@mcuadros
mcuadros / gist:5160940
Last active December 14, 2015 22:48
Benchmarking concatenation with heredoc, single-quoted and double-quoted

PHP 5.4.12 (cli) (built: Mar 8 2013 11:16:05)

Method heredoc 1000000 iterations in 1.970294 secs

$var = <<<EOT
<html><head><title>Benchmark Test Page</title></head><body bgcolor=
"$bgcolor" text="$textcolor" {$foo->bar()} link="$link"><p><font face="$fontface"
size="$fontsize"> Here is some test text for the web page.</font>
@mcuadros
mcuadros / gist:5212635
Last active December 15, 2015 05:59
How expensive is Reflection usage?

How expensive is Reflection usage?

Result:

  • Reflection 100000 iterations in 2.711766 secs
  • Sort of array(100) 100000 iterations in 1.949580 secs
  • Instance and Method call 100000 iterations in 0.284622 secs
@mcuadros
mcuadros / gist:5240520
Last active December 15, 2015 09:39
Benchmark from Skeetr early alpha version, Skeetr is PHP Application Server based on Gearmand + Nginx.

Skeetr 0.0.1 Benchmark

Benchmark from Skeetr early alpha version, Skeetr is PHP Application Server based on Gearmand + Nginx.

Setup

We make random requests over a Symfony2/Sonata [https://github.com/sonata-project/sandbox] sandbox project, some pages with MySQL, other MongoDB or none

Standard PHP:

@mcuadros
mcuadros / gist:5344879
Last active December 16, 2015 00:08
Basic example in PHP of Mongo 2.4 Text Search feature.
<?php
$m = new MongoClient(); // connect
$db = $collection = $m->foo; // get the database named "foo"
$collection = $db->bar; // get the collection "bar" from database named "foo"
$collection->ensureIndex(
array(
'title' => 'text',
'desc' => 'text',
@mcuadros
mcuadros / gist:5427447
Created April 20, 2013 21:10
Just playing with Go Flags (http://godoc.org/github.com/jessevdk/go-flags) an example with Commands
package main
import (
"fmt"
"github.com/jessevdk/go-flags"
"os"
"strings"
)
func main() {
@mcuadros
mcuadros / gist:5532049
Created May 7, 2013 11:55
#PHP odd: you can use any special char after a case like in PHP instead of ":", like a * a pipe, etc. Try it! "
<?php
//This is a valid PHP
switch (true) {
case 'semicolon'; //<-- Documented
false;
case 'asterisk'*
false;
case 'pipe'|
@mcuadros
mcuadros / gist:6877641
Created October 8, 2013 00:45
99 bottles = 232 chars = 2 hours missed @ http://www.phpgolf.org/challenge/99-Bottles

http://www.phpgolf.org/challenge/99-Bottles

<?$w=' on the wall';$c=' bottle';$p=$c.s;$b=' of beer';for($v=99;$v>0;print"$r$w, $r.\n".(--$v?"Take one down and pass it around, $v".($v>1?$p:$c)."$b$w.":"Go to the store and buy some more, 99$p$b$w.")."\n\n")$r=$v.($v>1?$p:$c).$b;
@mcuadros
mcuadros / gist:7234395
Created October 30, 2013 15:18
HHVM 2.2.0 + OSX 10.9 "ld: symbol(s) not found for architecture x86_64" issue
mcuadros@mcuadros-air /t/h/hhvm-HHVM-2.2> make test
[ 0%] [ 0%] Built target sqlite3
Generating systemlib.php
[ 1%] Built target double-conversion
[ 9%] Built target mbfl
[ 9%] Built target afdt
[ 10%] Built target timelib
[ 10%] Built target lz4
[ 10%] Built target hphp_parser
[ 11%] Built target neo
@mcuadros
mcuadros / gist:7476496
Last active December 28, 2015 09:09
Siren Level3 Example
{
"class": [
"discovery",
"product"
],
"title": "A. SAUVAGE royal panama cut away collar shirt grey",
"properties": {
"id": "527a355f1a9075a5778b4585",
"status": "published",
"visible": true,
@mcuadros
mcuadros / gist:9551290
Last active August 29, 2015 13:57
Mongofill Insert Benchmarks

MongoDB native driver 1.4.5 - PHP 5.5.9-1+sury.org~precise+1

Mongofill\Benchmarks\BsonEvent
    Method Name           Iterations    Average Time      Ops/second
    -------------------  ------------  --------------    -------------
    simpleEncode       : [10,000    ] [0.0000005092382] [1,963,717.40250]
    simpleNestedEncode : [10,000    ] [0.0000507833719] [19,691.48487]
    complexEncode      : [10,000    ] [0.0000015980959] [625,744.67768]
    complexNestedEncode: [10,000    ] [0.0001292291880] [7,738.18992]
    simpleDecode       : [10,000    ] [0.0000009249926] [1,081,089.77498]