Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "metadata": {
- "collapsed": true,
- "trusted": true
- },
- "cell_type": "code",
- "source": "import numpy as np",
- "execution_count": 1,
- "outputs": []
- },
- {
- "metadata": {
- "collapsed": true,
- "trusted": true
- },
- "cell_type": "code",
- "source": "import json",
- "execution_count": 2,
- "outputs": []
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": "## PHP code"
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": "<?php\n\n```\n\n$route = \\Drupal::service('router.route_provider')->getRouteByName('entity.node.canonical');\n$serialized = serialize($router);\n$arr = [$serialized, $serialized, $serialized];\n\n\n$times = [];\nfor ($i = 0; $i < 1000; $i++) {\n $start = microtime(TRUE);\n foreach ($arr as $element) {\n unserialize($element);\n }\n $end = microtime(TRUE);\n $times[] = $end - $start;\n}\n\nfile_put_contents('/tmp/test.txt', json_encode($times));\n\n```"
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": "## Before"
- },
- {
- "metadata": {
- "collapsed": true,
- "trusted": true
- },
- "cell_type": "code",
- "source": "data_before = json.load(open('/tmp/before.txt'))\ndata_before = np.array(data_before)",
- "execution_count": 17,
- "outputs": []
- },
- {
- "metadata": {
- "collapsed": false,
- "trusted": true
- },
- "cell_type": "code",
- "source": "print np.average(data_before), np.std(data_before)",
- "execution_count": 18,
- "outputs": [
- {
- "output_type": "stream",
- "text": "1.26051902771e-06 6.82836429677e-07\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {},
- "cell_type": "markdown",
- "source": "## After"
- },
- {
- "metadata": {
- "collapsed": true,
- "trusted": true
- },
- "cell_type": "code",
- "source": "data = json.load(open('/tmp/after.txt'))\ndata = np.array(data)",
- "execution_count": 19,
- "outputs": []
- },
- {
- "metadata": {
- "collapsed": false,
- "trusted": true
- },
- "cell_type": "code",
- "source": "print np.average(data), np.std(data)",
- "execution_count": 20,
- "outputs": [
- {
- "output_type": "stream",
- "text": "7.99655914307e-07 5.8840063032e-07\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {
- "collapsed": true,
- "trusted": true
- },
- "cell_type": "code",
- "source": "",
- "execution_count": null,
- "outputs": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "name": "python2",
- "display_name": "Python 2",
- "language": "python"
- },
- "language_info": {
- "mimetype": "text/x-python",
- "nbconvert_exporter": "python",
- "name": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.9",
- "file_extension": ".py",
- "codemirror_mode": {
- "version": 2,
- "name": "ipython"
- }
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement