Advertisement
Guest User

Untitled

a guest
May 25th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "metadata": {
  5. "collapsed": true,
  6. "trusted": true
  7. },
  8. "cell_type": "code",
  9. "source": "import numpy as np",
  10. "execution_count": 1,
  11. "outputs": []
  12. },
  13. {
  14. "metadata": {
  15. "collapsed": true,
  16. "trusted": true
  17. },
  18. "cell_type": "code",
  19. "source": "import json",
  20. "execution_count": 2,
  21. "outputs": []
  22. },
  23. {
  24. "metadata": {},
  25. "cell_type": "markdown",
  26. "source": "## PHP code"
  27. },
  28. {
  29. "metadata": {},
  30. "cell_type": "markdown",
  31. "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```"
  32. },
  33. {
  34. "metadata": {},
  35. "cell_type": "markdown",
  36. "source": "## Before"
  37. },
  38. {
  39. "metadata": {
  40. "collapsed": true,
  41. "trusted": true
  42. },
  43. "cell_type": "code",
  44. "source": "data_before = json.load(open('/tmp/before.txt'))\ndata_before = np.array(data_before)",
  45. "execution_count": 17,
  46. "outputs": []
  47. },
  48. {
  49. "metadata": {
  50. "collapsed": false,
  51. "trusted": true
  52. },
  53. "cell_type": "code",
  54. "source": "print np.average(data_before), np.std(data_before)",
  55. "execution_count": 18,
  56. "outputs": [
  57. {
  58. "output_type": "stream",
  59. "text": "1.26051902771e-06 6.82836429677e-07\n",
  60. "name": "stdout"
  61. }
  62. ]
  63. },
  64. {
  65. "metadata": {},
  66. "cell_type": "markdown",
  67. "source": "## After"
  68. },
  69. {
  70. "metadata": {
  71. "collapsed": true,
  72. "trusted": true
  73. },
  74. "cell_type": "code",
  75. "source": "data = json.load(open('/tmp/after.txt'))\ndata = np.array(data)",
  76. "execution_count": 19,
  77. "outputs": []
  78. },
  79. {
  80. "metadata": {
  81. "collapsed": false,
  82. "trusted": true
  83. },
  84. "cell_type": "code",
  85. "source": "print np.average(data), np.std(data)",
  86. "execution_count": 20,
  87. "outputs": [
  88. {
  89. "output_type": "stream",
  90. "text": "7.99655914307e-07 5.8840063032e-07\n",
  91. "name": "stdout"
  92. }
  93. ]
  94. },
  95. {
  96. "metadata": {
  97. "collapsed": true,
  98. "trusted": true
  99. },
  100. "cell_type": "code",
  101. "source": "",
  102. "execution_count": null,
  103. "outputs": []
  104. }
  105. ],
  106. "metadata": {
  107. "kernelspec": {
  108. "name": "python2",
  109. "display_name": "Python 2",
  110. "language": "python"
  111. },
  112. "language_info": {
  113. "mimetype": "text/x-python",
  114. "nbconvert_exporter": "python",
  115. "name": "python",
  116. "pygments_lexer": "ipython2",
  117. "version": "2.7.9",
  118. "file_extension": ".py",
  119. "codemirror_mode": {
  120. "version": 2,
  121. "name": "ipython"
  122. }
  123. }
  124. },
  125. "nbformat": 4,
  126. "nbformat_minor": 0
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement