From 093a2a306b3b0d536060e0bca23167d0c99dcd5a Mon Sep 17 00:00:00 2001
From: Neil Smith <neil.git@njae.me.uk>
Date: Wed, 26 Jul 2017 15:16:25 +0100
Subject: [PATCH] Added some timings

---
 07-interpreter/machine-code.ipynb | 94 ++++++++++++++++++++++---------
 1 file changed, 66 insertions(+), 28 deletions(-)

diff --git a/07-interpreter/machine-code.ipynb b/07-interpreter/machine-code.ipynb
index 69cd43f..2bb2223 100644
--- a/07-interpreter/machine-code.ipynb
+++ b/07-interpreter/machine-code.ipynb
@@ -416,17 +416,17 @@
     {
      "data": {
       "text/plain": [
-       "{'a': 0,\n",
-       " 1: 10,\n",
-       " 'pc': 6,\n",
-       " 'c': 20,\n",
+       "{1: 10,\n",
+       " 'a': 0,\n",
+       " 'b': 10,\n",
        " 'instructions': [(<function __main__.set_literal>, ['a', 10]),\n",
        "  (<function __main__.dec>, ['a']),\n",
        "  (<function __main__.inc>, ['b']),\n",
        "  (<function __main__.sto>, ['b', 1]),\n",
        "  (<function __main__.jpz>, ['a', 2]),\n",
        "  (<function __main__.jmp>, [-4])],\n",
-       " 'b': 10}"
+       " 'c': 20,\n",
+       " 'pc': 6}"
       ]
      },
      "execution_count": 22,
@@ -457,17 +457,17 @@
     {
      "data": {
       "text/plain": [
-       "{'a': 0,\n",
-       " 1: 10,\n",
-       " 'pc': 6,\n",
-       " 'c': 20,\n",
+       "{1: 10,\n",
+       " 'a': 0,\n",
+       " 'b': 10,\n",
        " 'instructions': [(<function __main__.set_literal>, ['a', 10]),\n",
        "  (<function __main__.dec>, ['a']),\n",
        "  (<function __main__.inc>, ['b']),\n",
        "  (<function __main__.sto>, ['b', 1]),\n",
        "  (<function __main__.jpz>, ['a', 2]),\n",
        "  (<function __main__.jmp>, [-4])],\n",
-       " 'b': 10}"
+       " 'c': 20,\n",
+       " 'pc': 6}"
       ]
      },
      "execution_count": 23,
@@ -658,7 +658,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 39,
+   "execution_count": 28,
    "metadata": {},
    "outputs": [
     {
@@ -667,7 +667,7 @@
        "'1: 0, a: 0, b: 0, c: 27, pc: 11'"
       ]
      },
-     "execution_count": 39,
+     "execution_count": 28,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -696,7 +696,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 40,
+   "execution_count": 29,
    "metadata": {},
    "outputs": [
     {
@@ -725,7 +725,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 29,
+   "execution_count": 30,
    "metadata": {},
    "outputs": [
     {
@@ -734,7 +734,7 @@
        "'1: 0, a: 0, b: 0, c: 10, pc: 13'"
       ]
      },
-     "execution_count": 29,
+     "execution_count": 30,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -765,7 +765,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 30,
+   "execution_count": 31,
    "metadata": {},
    "outputs": [
     {
@@ -798,7 +798,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 31,
+   "execution_count": 32,
    "metadata": {},
    "outputs": [
     {
@@ -807,7 +807,7 @@
        "'1: 0, a: 52, b: 0, c: 0, pc: 48'"
       ]
      },
-     "execution_count": 31,
+     "execution_count": 32,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -889,7 +889,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 32,
+   "execution_count": 33,
    "metadata": {},
    "outputs": [
     {
@@ -898,7 +898,7 @@
        "40"
       ]
      },
-     "execution_count": 32,
+     "execution_count": 33,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -909,7 +909,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 33,
+   "execution_count": 34,
    "metadata": {
     "collapsed": true
    },
@@ -930,7 +930,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 34,
+   "execution_count": 35,
    "metadata": {},
    "outputs": [
     {
@@ -939,7 +939,7 @@
        "52"
       ]
      },
-     "execution_count": 34,
+     "execution_count": 35,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -950,7 +950,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 35,
+   "execution_count": 36,
    "metadata": {},
    "outputs": [
     {
@@ -959,7 +959,7 @@
        "(250504, 937)"
       ]
      },
-     "execution_count": 35,
+     "execution_count": 36,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -970,7 +970,27 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 36,
+   "execution_count": 41,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "(52, 9)"
+      ]
+     },
+     "execution_count": 41,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "max([(max_collatz(i), i) for i in range(1, 10)])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 37,
    "metadata": {
     "scrolled": true
    },
@@ -1079,7 +1099,7 @@
        " (99, 0, 448)]"
       ]
      },
-     "execution_count": 36,
+     "execution_count": 37,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -1116,7 +1136,25 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 40,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "1 loop, best of 3: 38.6 s per loop\n"
+     ]
+    }
+   ],
+   "source": [
+    "%%timeit\n",
+    "show_machine(execute(program, initial_state={'a': 937}))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 39,
    "metadata": {
     "collapsed": true
    },
-- 
2.43.0