Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Side by Side Diff: bower_components/gif.js/src/benchmark.coffee

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 {NeuQuant} = require './TypedNeuQuant.js'
2
3 ###
4 typed 100 runs:
5 run finished at q1
6 avg: 661.46ms median: 660.54ms
7 run finished at q10
8 avg: 67.49ms median: 67.03ms
9 run finished at q20
10 avg: 34.56ms median: 34.19ms
11 normal 100 runs:
12 run finished at q1
13 avg: 888.10ms median: 887.63ms
14 run finished at q10
15 avg: 92.85ms median: 91.99ms
16 run finished at q20
17 avg: 46.14ms median: 45.68ms
18 ###
19
20 quality = 10 # pixel sample interval, 1 being the best quality
21 runs = 100
22
23 if window.performance?.now?
24 now = -> window.performance.now()
25 else
26 now = Date.now
27
28 window.addEventListener 'load', ->
29 img = document.getElementById 'image'
30 canvas = document.getElementById 'canvas'
31
32 w = canvas.width = img.width
33 h = canvas.height = img.height
34
35 ctx = canvas.getContext('2d')
36 ctx.drawImage(img, 0, 0)
37
38 imdata = ctx.getImageData(0, 0, img.width, img.height)
39 rgba = imdata.data
40
41 rgb = new Uint8Array w * h * 3
42 #rgb = new Array w * h * 3
43
44 rgb_idx = 0
45 for i in [0...rgba.length] by 4
46 rgb[rgb_idx++] = rgba[i + 0]
47 rgb[rgb_idx++] = rgba[i + 1]
48 rgb[rgb_idx++] = rgba[i + 2]
49
50 runtimes = []
51 for run in [0...runs]
52 start = now()
53 imgq = new NeuQuant rgb, quality
54 imgq.buildColormap()
55 end = now()
56 delta = end - start
57 runtimes.push delta
58
59 console.log runtimes.join('\n')
60
61 map = imgq.getColormap()
62 avg = runtimes.reduce((p, n) -> p + n) / runtimes.length
63 median = runtimes.sort()[Math.floor(runs / 2)]
64 console.log """
65 run finished at q#{ quality }
66 avg: #{ avg.toFixed(2) }ms median: #{ median.toFixed(2) }ms
67 """
68
69 for y in [0...h]
70 for x in [0...w]
71 idx = (y * w + x) * 4
72
73 r = rgba[idx + 0]
74 g = rgba[idx + 1]
75 b = rgba[idx + 2]
76
77 map_idx = imgq.lookupRGB(r, g, b) * 3
78
79 rgba[idx + 0] = map[map_idx]
80 rgba[idx + 1] = map[map_idx + 1]
81 rgba[idx + 2] = map[map_idx + 2]
82
83 ctx.putImageData imdata, 0, 0
84
85 for i in [0...map.length] by 3
86 color = [map[i], map[i + 1], map[i + 2]]
87 el = document.createElement 'span'
88 el.style.display = 'inline-block'
89 el.style.height = '1em'
90 el.style.width = '1em'
91 el.style.background = 'rgb(' + color.join(',') + ')'
92 document.body.appendChild el
OLDNEW
« no previous file with comments | « bower_components/gif.js/src/TypedNeuQuant.js ('k') | bower_components/gif.js/src/browser.coffee » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698