Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove regexp test & only support v4, v6 #66

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open

Conversation

JacksonTian
Copy link
Contributor

No description provided.

@mention-bot
Copy link

@JacksonTian, thanks for your PR! By analyzing the annotation information on this pull request, we identified @fengmk2, @dead-horse and @shaoshuai0102 to be potential reviewers

@JacksonTian
Copy link
Contributor Author

看来需要先hold住这个patch。

'use strict';

/**
 * Module dependencies.
 */

var Benchmark = require('benchmark');
var benchmarks = require('beautify-benchmark');


var regexp = function (type) {
  return /Exception$/.test(type) || /^java\.lang\.\w+Error$/.test(type);
};

var xwith = function (type) {
  return type.endsWith('Exception') || (type.endsWith('Error') && type.startsWith('java.lang.'));
};

var suite = new Benchmark.Suite();

suite

.add('regexp: java.util.ArrayList', function() {
  regexp('java.util.ArrayList');
})
.add('xwith: java.util.ArrayList', function() {
  xwith('java.util.ArrayList');
})

.add('regexp: com.alibaba.TESTObject', function() {
  regexp('com.alibaba.TESTObject');
})
.add('xwith: com.alibaba.TESTObject', function() {
  xwith('com.alibaba.TESTObject');
})

.add('regexp: java.lang.NoClassDefFoundError', function() {
  regexp('java.lang.NoClassDefFoundError');
})
.add('xwith: java.lang.NoClassDefFoundError', function() {
  xwith('java.lang.NoClassDefFoundError');
})

.add('regexp: java.io.IOException', function() {
  regexp('java.io.IOException');
})
.add('xwith: java.io.IOException', function() {
  xwith('java.io.IOException');
})

.on('cycle', function(event) {
  benchmarks.add(event.target);
})
.on('start', function(event) {
  console.log('\n  node version: %s, date: %s\n  Starting...',
    process.version, Date());
})
.on('complete', function done() {
  benchmarks.log();
})
.run({ 'async': false });
hessian.js $ node benchmark/regexp_vs_with.js 


  node version: v6.4.0, date: Wed Aug 24 2016 11:14:21 GMT+0800 (CST)
  Starting...
  8 tests completed.

  regexp: java.util.ArrayList            x  9,365,011 ops/sec ±1.58% (90 runs sampled)
  xwith: java.util.ArrayList             x  9,434,344 ops/sec ±1.67% (88 runs sampled)
  regexp: com.alibaba.TESTObject         x  8,459,659 ops/sec ±1.92% (89 runs sampled)
  xwith: com.alibaba.TESTObject          x 10,081,475 ops/sec ±1.61% (89 runs sampled)
  regexp: java.lang.NoClassDefFoundError x  7,038,646 ops/sec ±1.08% (98 runs sampled)
  xwith: java.lang.NoClassDefFoundError  x  5,008,162 ops/sec ±1.65% (93 runs sampled)
  regexp: java.io.IOException            x 13,976,183 ops/sec ±2.96% (95 runs sampled)
  xwith: java.io.IOException             x 12,927,316 ops/sec ±1.48% (85 runs sampled)

hessian.js $ tnvm use node-v4.5.0
Now using node node-v4.5.0 (npm v2.15.9)
hessian.js $ node benchmark/regexp_vs_with.js 


  node version: v4.5.0, date: Wed Aug 24 2016 11:16:14 GMT+0800 (CST)
  Starting...
  8 tests completed.

  regexp: java.util.ArrayList            x 10,596,364 ops/sec ±1.66% (89 runs sampled)
  xwith: java.util.ArrayList             x  6,064,788 ops/sec ±1.51% (87 runs sampled)
  regexp: com.alibaba.TESTObject         x  9,656,040 ops/sec ±1.81% (88 runs sampled)
  xwith: com.alibaba.TESTObject          x  5,047,786 ops/sec ±1.60% (87 runs sampled)
  regexp: java.lang.NoClassDefFoundError x  6,410,909 ops/sec ±3.05% (83 runs sampled)
  xwith: java.lang.NoClassDefFoundError  x  3,136,805 ops/sec ±1.76% (86 runs sampled)
  regexp: java.io.IOException            x 14,832,236 ops/sec ±1.65% (89 runs sampled)
  xwith: java.io.IOException             x 10,196,105 ops/sec ±1.95% (87 runs sampled)

starts/endsWith比正则表达式快需要一些条件:

  • V8的优化。目前4.x下的V8明显不适合。
  • unmatch的情况下,starts/ends更有优势。
  • 参数长度越短,越有优势。

@fengmk2
Copy link
Member

fengmk2 commented Aug 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants