Skip to content

Instantly share code, notes, and snippets.

View mcuadros's full-sized avatar

Máximo Cuadros mcuadros

View GitHub Profile
<?hh
type Example = (function(): string);
function main() {
$callback = function() {
return 'foo';
};
@mcuadros
mcuadros / gist:10937820
Created April 16, 2014 22:06
pimple-hack vs pimple (HHVM vs PHP)

pimple-hack vs pimple

Just as a learning practice, i made this port of pimple for hack, this are the results of my little benchmarks based on 1 million of iterations.

The code

void bsonToMongoId(bson_iter_t* iter, Array* output) {
    const bson_oid_t* oid = bson_iter_oid(iter);
    char id[25];

    bson_oid_to_string(oid, id);
   
    TypedValue ret;
    Class* cls = Unit::loadClass(s_MongoId.get());
 ObjectData* obj = ObjectData::newInstance(cls);
@mcuadros
mcuadros / gist:9633632
Created March 19, 2014 01:14
Doctrine Benchmarks @ HHVM + Mongofill

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

Doctrine\Benchmarks\InsertingEvent
    Method Name             Iterations    Average Time      Ops/second
    ---------------------  ------------  --------------    -------------
    simpleDocument       : [400       ] [0.0039921021461] [250.49459]
    complexDocument      : [400       ] [0.0344979619980] [28.98722]
    complexNestedDocument: [400       ] [0.5473231738806] [1.82707]

@mcuadros
mcuadros / gist:9604673
Last active August 29, 2015 13:57
stream_get_meta_data behavior

fopen

Code

<?php
$fp = fsockopen("www.example.com", 80);
if (!$fp) {
    echo "Unable to open\n";
 exit();
@mcuadros
mcuadros / gist:9560576
Last active August 29, 2015 13:57
Mongator Benchmarks @ HHVM + Mongofill

Mongator Benchmarks @ HHVM + Mongofill

Mongator is a simple MongoDB ODM to claims to be 3x faster than Doctrine, now thanks to Mongofill a pure PHP implementation of MongoDB driver, is possible run this package under HHVM.

The benchmarks, are based on athletic.

The native version uses the standard mongo driver, and HHVM is running the lastest mastver version with Mongofill ae5c155 + bson-hni 0.0.1

A bencmarks of a plain version of mongofill can be found at https://gist.github.com/mcuadros/9551290

@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]
@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: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: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;