Last active
September 13, 2017 01:44
-
-
Save rockpunk/3c8ff2d03c5a19b4043f9d1c18e0929e to your computer and use it in GitHub Desktop.
passing data between two interpreted languages
This file contains hidden or 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
#!/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; | |
} |
This file contains hidden or 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
#!/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) |
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment