Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 23,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import re\n",
  10. "\n",
  11. "a = ' '.join(str(x) for x in range(4 * 10))\n",
  12. "\n",
  13. "f_pt = re.compile(r'\\d+ \\d+ \\d+ \\d+')\n",
  14. "g_pt = re.compile(r'(\\d+) (\\d+) (\\d+) (\\d+)')\n",
  15. "\n",
  16. "def f(a):\n",
  17. " return [[int(i) for i in x[0].split(' ')] for x in f_pt.finditer(a)]\n",
  18. "\n",
  19. "def g(a):\n",
  20. " return [[int(i) for i in x.groups()] for x in g_pt.finditer(a)]\n",
  21. "\n",
  22. "def h(a):\n",
  23. " def _(a):\n",
  24. " while a:\n",
  25. " w, x, y, z, *a = a\n",
  26. " yield w, x, y, z\n",
  27. " return list(_(a.split(' ')))\n",
  28. "\n",
  29. "def h_(a):\n",
  30. " while a:\n",
  31. " w, x, y, z, *a = a\n",
  32. " yield w, x, y, z\n",
  33. "\n",
  34. "def h2(a, _):\n",
  35. " return list(_(a.split(' ')))\n",
  36. " "
  37. ]
  38. },
  39. {
  40. "cell_type": "code",
  41. "execution_count": 24,
  42. "metadata": {},
  43. "outputs": [
  44. {
  45. "name": "stdout",
  46. "output_type": "stream",
  47. "text": [
  48. "19.9 µs ± 285 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
  49. ]
  50. }
  51. ],
  52. "source": [
  53. "%timeit f(a)"
  54. ]
  55. },
  56. {
  57. "cell_type": "code",
  58. "execution_count": 25,
  59. "metadata": {},
  60. "outputs": [
  61. {
  62. "name": "stdout",
  63. "output_type": "stream",
  64. "text": [
  65. "21.6 µs ± 1.54 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
  66. ]
  67. }
  68. ],
  69. "source": [
  70. "%timeit g(a)"
  71. ]
  72. },
  73. {
  74. "cell_type": "code",
  75. "execution_count": 26,
  76. "metadata": {},
  77. "outputs": [
  78. {
  79. "name": "stdout",
  80. "output_type": "stream",
  81. "text": [
  82. "5.79 µs ± 344 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
  83. ]
  84. }
  85. ],
  86. "source": [
  87. "%timeit h(a)"
  88. ]
  89. },
  90. {
  91. "cell_type": "code",
  92. "execution_count": 27,
  93. "metadata": {},
  94. "outputs": [
  95. {
  96. "name": "stdout",
  97. "output_type": "stream",
  98. "text": [
  99. "5.92 µs ± 266 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
  100. ]
  101. }
  102. ],
  103. "source": [
  104. "%timeit h2(a, h_)"
  105. ]
  106. },
  107. {
  108. "cell_type": "code",
  109. "execution_count": null,
  110. "metadata": {
  111. "collapsed": true
  112. },
  113. "outputs": [],
  114. "source": []
  115. }
  116. ],
  117. "metadata": {
  118. "kernelspec": {
  119. "display_name": "Python 3",
  120. "language": "python",
  121. "name": "python3"
  122. },
  123. "language_info": {
  124. "codemirror_mode": {
  125. "name": "ipython",
  126. "version": 3
  127. },
  128. "file_extension": ".py",
  129. "mimetype": "text/x-python",
  130. "name": "python",
  131. "nbconvert_exporter": "python",
  132. "pygments_lexer": "ipython3",
  133. "version": "3.6.2"
  134. }
  135. },
  136. "nbformat": 4,
  137. "nbformat_minor": 2
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement