Skip to content

Instantly share code, notes, and snippets.

@rockpunk
Last active September 13, 2017 01:44

Revisions

  1. rockpunk revised this gist Sep 13, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions timing.txt
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,12 @@ cru@mclappy:~ $ for y in tmp stdin arg; do time for x in {1..100}; do ./junk.php

    real 0m11.431s
    user 0m9.040s
    sys 0m2.011s
    sys 0m2.011s

    real 0m11.335s
    user 0m9.015s
    sys 0m1.959s
    sys 0m1.959s

    real 0m14.142s
    user 0m11.556s
    sys 0m2.199s
    sys 0m2.199s
  2. rockpunk created this gist Sep 13, 2017.
    34 changes: 34 additions & 0 deletions junk.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/usr/bin/env php
    <?php

    $n=10;
    $meth=$argv[1];

    if($argv[2]) {
    $n=$argv[2];
    }

    $str='str';
    for($i=0;$i<$n-5;$i++) {
    $str.="i";
    }
    $str .= "ng";

    switch($meth) {
    case 'arg':
    system('./junk.py -s ' . $str);
    break;
    case 'tmp':
    $fname = tempnam('/tmp','junk');
    $f = fopen($fname,'wb');
    fwrite($f, $str);
    fclose($f);

    system('./junk.py -f ' . $fname);
    break;
    case 'stdin':
    $f = popen('./junk.py','wb');
    fwrite($f, $str);
    pclose($f);
    break;
    }
    27 changes: 27 additions & 0 deletions junk.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env python

    import argparse
    import os
    import sys

    p = argparse.ArgumentParser()
    p.add_argument('-f')
    p.add_argument('-s')
    opts = p.parse_args()

    f=None
    if opts.f:
    f = open(opts.f, 'rb')
    elif opts.s:
    s = opts.s
    else:
    f = sys.stdin

    if f:
    s = f.read()
    # force some work in mem
    b = len(''.join(s.upper()[::-1].split()))
    print "hey, got %s bytes" % b

    if opts.f:
    os.unlink(opts.f)
    13 changes: 13 additions & 0 deletions timing.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    cru@mclappy:~ $ for y in tmp stdin arg; do time for x in {1..100}; do ./junk.php $y 200000 > /dev/null; done; done

    real 0m11.431s
    user 0m9.040s
    sys 0m2.011s

    real 0m11.335s
    user 0m9.015s
    sys 0m1.959s

    real 0m14.142s
    user 0m11.556s
    sys 0m2.199s