Skip to content

Commit 77bbc91

Browse files
committed
Fix a few more typos, change date.
Plan to publish tomorrow.
1 parent b9486b1 commit 77bbc91

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

_posts/blog/2015-09-27-surprises-in-gopherjs-performance.mdown renamed to _posts/blog/2015-09-28-surprises-in-gopherjs-performance.mdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: "Surprises in GopherJS Performance"
4-
date: 2015-09-27
4+
date: 2015-09-28
55
author: Dmitri Shuralyov
66
---
77

@@ -100,14 +100,14 @@ So I looked at how [Go implements it](http://gotools.org/math#Pow).
100100
Pretty straightforward Go code.
101101
Now I knew GopherJS uses some JavaScript native APIs to implement parts of the standard library, so I checked how [it implemented `math.Pow`](https://github.com/gopherjs/gopherjs/blob/master/compiler/natives/math/math.go#L157).
102102
Aha! It's not the same code after all.
103-
GopherJS implements it by using [JavaScript's `Math` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math), so it translates to:
103+
GopherJS implements it by using [JavaScript's `Math` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math), so it translates to the following JavaScript code:
104104

105105
```JavaScript
106106
Math.pow(x, y)
107107
```
108108

109109
That's when it hit me.
110-
In this code, which was taken from a snippet that optimized for brevity and demonstration purposes rather than performance, `math.Pow` was being used with th first argument of -1, and the second argument are values 0, 1, 2, 3, etc., in sequence.
110+
In this code, which was taken from a snippet that optimized for brevity and demonstration purposes rather than performance, `math.Pow` was being used with the first argument of -1, and the second argument are values 0, 1, 2, 3, etc., in sequence.
111111
The output of that is an alternating sequence of 1, -1, 1, -1, 1, -1, etc.
112112
But using `math.Pow` for that is extremely inefficient, since it's meant to work with arbitrary inputs that are much harder to calculate.
113113
This can be trivially rewritten with an if statement.
@@ -190,7 +190,7 @@ total time taken is: 6.549s
190190

191191
As expected, the GopherJS time did not change because it was a no-op, but the native Go performance has now caught up to the GopherJS version!
192192

193-
Just to be sure, I wanted to see if 6.5 seconds was as fast as these 1 billion iterations could happen, even if you were to implement this in a low level language like C:
193+
Just to be sure, I wanted to see if 6.5 seconds was as fast as these 1 billion iterations could happen, even if you were to implement this in a low-level language like C:
194194

195195
```C
196196
#include <stdio.h>

0 commit comments

Comments
 (0)