Improve performance #4

Merged
merged 8 commits into from Sep 14, 2016

Projects

None yet

2 participants

@haya14busa
Owner

No description provided.

added some commits Sep 14, 2016
@haya14busa add benchmark 36af432
@haya14busa use builtin len instead of viml_len to avoid allocations
benchmark                            old ns/op     new ns/op     delta
BenchmarkVimLParser_VimLParser-4     522557385     384606362     -26.40%
ce9df41
@coveralls

Coverage Status

Coverage decreased (-0.02%) to 81.585% when pulling ce9df41 on performance into 91d84c9 on master.

@coveralls

Coverage Status

Coverage decreased (-0.02%) to 81.585% when pulling ce9df41 on performance into 91d84c9 on master.

added some commits Sep 14, 2016
@haya14busa little improvement of viml_split
before:

         .          .    140:func viml_split(s string, sep string) []string {
         .          .    141:   if sep == `\zs` {
         .          .    142:           var ss []string
         .          .    143:           for _, r := range s {
   58.05MB    58.05MB    144:                   ss = append(ss, string(r))
         .          .    145:           }
         .          .    146:           return ss
         .          .    147:   }
         .          .    148:   panic("NotImplemented viml_split")
         .          .    149:}

after:

         .          .    140:func viml_split(s string, sep string) []string {
         .          .    141:   if sep == `\zs` {
   21.02MB    21.02MB    142:           ss := make([]string, 0, len(s))
         .          .    143:           for _, r := range s {
       4MB        4MB    144:                   ss = append(ss, string(r))
         .          .    145:           }
         .          .    146:           return ss
         .          .    147:   }
         .          .    148:   panic("NotImplemented viml_split")
         .          .    149:}
c18ec64
@haya14busa write StringReader.__init__() by hand and use &pos{} instead of []int…
…erface{}{lnum, col}

benchmark                            old ns/op     new ns/op     delta
BenchmarkVimLParser_VimLParser-4     366894571     295205749     -19.54%
15f9979
@haya14busa initialize StringReader.buf and StringReader.pos size in advance
benchmark                            old ns/op     new ns/op     delta
BenchmarkVimLParser_VimLParser-4     295205749     262219875     -11.17%
5d93cfd
@haya14busa use pos instead of *pos internally in StringReader
benchmark                            old ns/op     new ns/op     delta
BenchmarkVimLParser_VimLParser-4     262219875     248887206     -5.08%
331a0fe
@haya14busa use range {string} instead of viml_split({string}, "\\zs")
benchmark                            old ns/op     new ns/op     delta
BenchmarkVimLParser_VimLParser-4     248887206     235228838     -5.49%
71f910d
@haya14busa
Owner
# benchcmp mem.0 mem.8                                                                                                                                                    (git)-[performance]
benchmark                            old ns/op     new ns/op     delta
BenchmarkVimLParser_VimLParser-4     522557385     239071919     -54.25%
@haya14busa fix StringReader.__init__ initialization of buf and pos
1dc4167
@coveralls

Coverage Status

Coverage increased (+0.03%) to 81.626% when pulling 71f910d on performance into 91d84c9 on master.

@coveralls

Coverage Status

Coverage increased (+0.03%) to 81.626% when pulling 71f910d on performance into 91d84c9 on master.

@coveralls

Coverage Status

Coverage increased (+0.03%) to 81.626% when pulling 1dc4167 on performance into 91d84c9 on master.

@coveralls

Coverage Status

Coverage increased (+0.03%) to 81.626% when pulling 1dc4167 on performance into 91d84c9 on master.

@haya14busa
Owner

Benchmarks

$ pwd
/home/haya14busa/src/github.com/ynkdir/vim-vimlparser

$ git rev-parse HEAD
2fff43c58968a18bc01bc8304df68bde01af04d9

$ wc -l < autoload/vimlparser.vim
5195

$ time vim -u NONE -N --cmd "let &rtp .= ',' . getcwd()" --cmd "silent call vimlparser#test('autoload/vimlparser.vim')" -c ":q"
vim -u NONE -N --cmd "let &rtp .= ',' . getcwd()" --cmd  -c ":q"  48.88s user 0.05s system 99% cpu 48.942 total

$ python3 -V
Python 3.5.0

$ time python3 py/vimlparser.py autoload/vimlparser.vim > /dev/null
python3 py/vimlparser.py autoload/vimlparser.vim > /dev/null  4.17s user 0.04s system 99% cpu 4.236 total

$ pypy3 -V
Python 3.2.5 (b2091e973da69152b3f928bfaabd5d2347e6df46, Mar 04 2016, 07:08:30)
[PyPy 2.4.0 with GCC 5.3.0]

$ time pypy3 py/vimlparser.py autoload/vimlparser.vim > /dev/null
pypy3 py/vimlparser.py autoload/vimlparser.vim > /dev/null  2.63s user 0.06s system 99% cpu 2.694 total

$ node --version
v4.2.3

$ time node js/vimlparser.js autoload/vimlparser.vim > /dev/null
node js/vimlparser.js autoload/vimlparser.vim > /dev/null  0.77s user 0.04s system 125% cpu 0.644 total

$ go get github.com/haya14busa/go-vimlparser/cmd/vimlparser
$ time vimlparser autoload/vimlparser.vim > /dev/null
vimlparser autoload/vimlparser.vim > /dev/null  0.36s user 0.02s system 125% cpu 0.299 total
Language Time (sec)
Vim script 48.88s
Python3 (3.5.0) 4.17s
pypy3 2.63s
node 0.77s
go 0.36s

Something Extra

$ pwd
/home/haya14busa/src/github.com/haya14busa/go-vimlparser

$ git rev-parse HEAD
db7e1558c2c9a2a85b8b61bbfd2550f348b5677e

$ time go run cmd/vimlparser/main.go ../../ynkdir/vim-vimlparser/autoload/vimlparser.vim > /dev/null
go run cmd/vimlparser/main.go  > /dev/null  0.54s user 0.08s system 124% cpu 0.491 total

Go is the fastest even with compile time.

@haya14busa haya14busa merged commit 33fd88f into master Sep 14, 2016

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 81.626%
Details
@haya14busa haya14busa deleted the performance branch Sep 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment