From 34b6494106ba0018ad5d8d8c8c0e8fc640c17e52 Mon Sep 17 00:00:00 2001 From: Alexander Chekunkov Date: Mon, 3 Aug 2015 11:52:17 +0300 Subject: [PATCH] Add benchmark notebook to benchmark/notebooks It respects #185 (not merged yet) and looks like a good place for benchmark notebook --- .gitignore | 6 +- .../notebooks/Benchmark PNG vs JPEG.ipynb | 501 ++++++++++++++++++ 2 files changed, 506 insertions(+), 1 deletion(-) create mode 100644 benchmark/notebooks/Benchmark PNG vs JPEG.ipynb diff --git a/.gitignore b/.gitignore index 52cc66caa..736a2a08d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,9 @@ _trial_temp .ipynb_checkpoints .splash-cache* .coverage -notebooks + +# virtual environments env* + +# IPython notebooks +/notebooks/ diff --git a/benchmark/notebooks/Benchmark PNG vs JPEG.ipynb b/benchmark/notebooks/Benchmark PNG vs JPEG.ipynb new file mode 100644 index 000000000..767e73263 --- /dev/null +++ b/benchmark/notebooks/Benchmark PNG vs JPEG.ipynb @@ -0,0 +1,501 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "function min( a )\n", + " table.sort( a )\n", + " return a[1]\n", + "end\n", + "\n", + "function max( a )\n", + " table.sort( a )\n", + " return a[#a]\n", + "end\n", + "\n", + "function mean( a )\n", + " local sum = 0\n", + " local count= 0\n", + " for i, x in ipairs(a) do\n", + " sum = sum + x\n", + " count = count + 1\n", + " end\n", + " return (sum / count)\n", + "end\n", + "\n", + "function median( a )\n", + " table.sort( a )\n", + " if math.fmod(#a,2) == 0 then\n", + " -- return mean value of middle two elements\n", + " return ( a[#a/2] + a[(#a/2)+1] ) / 2\n", + " else\n", + " -- return middle element\n", + " return a[math.ceil(#a/2)]\n", + " end\n", + "end\n", + "\n", + "function stats( a )\n", + " return string.format(\"min: %.4f, max: %.4f, mean: %.4f, median: %.4f\", min(a), max(a), mean(a), median(a))\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "'http://scrapy.org/'" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "ok, reason = splash:go('http://scrapy.org/')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Wait until page is loaded**" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.0517, max: 0.0843, mean: 0.0565, median: 0.0557\"" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:png()\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.0272, max: 0.0498, mean: 0.0300, median: 0.0291\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg()\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.0337, max: 0.0436, mean: 0.0366, median: 0.0362\"" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{quality=100}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.0294, max: 0.0355, mean: 0.0310, median: 0.0304\"" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{quality=90}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.0243, max: 0.0626, mean: 0.0268, median: 0.0257\"" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{quality=10}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.0234, max: 0.0358, mean: 0.0248, median: 0.0244\"" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{quality=0}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "https://blog.pinterest.com/en" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "splash:go('https://blog.pinterest.com/en')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Wait until page is loaded**" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 1.2306, max: 1.4108, mean: 1.2754, median: 1.2704\"" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:png{render_all=1}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.3688, max: 0.7227, mean: 0.3973, median: 0.3933\"" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{render_all=1}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 0.4002, max: 0.4698, mean: 0.4172, median: 0.4150\"" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{render_all=1, quality=90}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "http://www.w3.org/TR/2010/REC-xhtml-basic-20101123/" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "splash:go('http://www.w3.org/TR/2010/REC-xhtml-basic-20101123/')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Wait until page is fully loaded**" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 4.0079, max: 4.4050, mean: 4.1070, median: 4.0956\"" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:png{render_all=1}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 2.7935, max: 3.2204, mean: 2.9226, median: 2.9043\"" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{render_all=1}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"min: 3.0926, max: 3.5423, mean: 3.2221, median: 3.1808\"" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = {}\n", + "for i=1,100 do\n", + " local x = os.clock()\n", + " splash:jpeg{render_all=1, quality=90}\n", + " a[i] = os.clock() - x\n", + "end\n", + "stats(a)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Splash", + "language": "lua", + "name": "splash" + }, + "language_info": { + "codemirror_mode": { + "name": "text/x-lua" + }, + "display_name": "Splash", + "file_extension": ".lua", + "language": "lua", + "mimetype": "application/x-lua", + "name": "Splash", + "pygments_lexer": "lua" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}