Updated test
This commit is contained in:
125
test/benchmarks/basic.bench.js
Normal file
125
test/benchmarks/basic.bench.js
Normal file
@ -0,0 +1,125 @@
|
||||
'use strict'
|
||||
|
||||
const bench = require('nanobench')
|
||||
const { Client } = require('../../index')
|
||||
const { connection } = require('../utils')
|
||||
|
||||
bench('Initialization', { repetitions: 5 }, b => {
|
||||
const client = new Client({ // eslint-disable-line
|
||||
node: 'http://localhost:9200'
|
||||
})
|
||||
b.end()
|
||||
})
|
||||
|
||||
bench('Call api with lazy loading', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
b.start()
|
||||
client.info((err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
|
||||
bench('Call api without lazy loading', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
client.info((err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.start()
|
||||
client.info((err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
bench('Basic get', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
// we run the method twice to skip the lazy loading overhead
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
q: 'foo:bar'
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.start()
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
q: 'foo:bar'
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
bench('Basic post', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
// we run the method twice to skip the lazy loading overhead
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.start()
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user