Skip to content

Commit

Permalink
A very crude performance test.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Jul 3, 2012
1 parent 2ad31c1 commit d7dd319
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -24,6 +24,7 @@
"node": "0.6 || 0.7"
},
"dependencies": {
"async": "0.1.22",
"iconv-lite": "0.2.0",
"sprintf": "0.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/sqlbatch-payload.coffee
Expand Up @@ -12,7 +12,7 @@ class SqlBatchPayload
buffer = new WritableTrackingBuffer(100 + (2 * @sqlText.length), 'ucs2')
writeAllHeaders(buffer, txnDescriptor, outstandingRequestCount)
buffer.writeString(@sqlText, 'ucs2')

@data = buffer.data

toString: (indent) ->
Expand Down
2 changes: 1 addition & 1 deletion src/token/token-stream-parser.coffee
Expand Up @@ -18,7 +18,7 @@ tokenParsers[TYPE.ROW] = require('./row-token-parser')

###
Buffers are thrown at the parser (by calling addBuffer).
Tokens are parsed from the buffer until there are no more tokens in
Tokens are parsed from the buffer until there are no more tokens in
the buffer, or there is just a partial token left.
If there is a partial token left over, then it is kept until another
buffer is added, which should contain the remainder of the partial
Expand Down
90 changes: 90 additions & 0 deletions test/performance/big-select.coffee
@@ -0,0 +1,90 @@
Connection = require('../../src/connection')
Request = require('../../src/request')
fs = require('fs')
async = require('async')

getConfig = ->
JSON.parse(fs.readFileSync(process.env.HOME + '/.tedious/test-connection.json', 'utf8')).config

exports.lotsOfRows = (test) ->
test.expect(2)
rows = 50000

createTableSql = 'create table #many_rows (id int, first_name varchar(20), last_name varchar(20))'
insertRowsSql = """
declare @count int
set @count = #{rows}
while @count > 0
begin
insert into #many_rows (id, first_name, last_name) values(@count, 'MyFirstName', 'YourLastName')
set @count = @count - 1
end
"""
selectSql = 'select * from #many_rows'

config = getConfig()
connection = new Connection(config)

createTable = (callback) ->
request = new Request(createTableSql, (err, rowCount) ->
callback(err)
)

console.log 'Creating table'
connection.execSqlBatch(request)

insertRows = (callback) ->
request = new Request(insertRowsSql, (err, rowCount) ->
callback(err)
)

console.log 'Inserting rows'
connection.execSqlBatch(request)

select = (callback) ->
start = Date.now()
request = new Request(selectSql, (err, rowCount) ->
test.strictEqual(rows, rowCount)

durationMillis = Date.now() - start
console.log "Took #{durationMillis / 1000}s"
console.log "#{rows / (durationMillis / 1000)} rows/sec"

callback(err)
)

request.on('row', (columns) ->
#console.log(columns[0].value)
)

console.log 'Selecting rows'
connection.execSqlBatch(request)

connection.on('connect', (err) ->
test.ok(!err)

async.series([
createTable,
insertRows,
select,
() ->
connection.close()
]);
)

connection.on('end', (info) ->
test.done()
)

connection.on('infoMessage', (info) ->
#console.log("#{info.number} : #{info.message}")
)

connection.on('errorMessage', (error) ->
#console.log("#{error.number} : #{error.message}")
)

connection.on('debug', (text) ->
#console.log(text)
)

0 comments on commit d7dd319

Please sign in to comment.