Last active
August 29, 2015 14:15
-
-
Save tommy351/48401ae93dbf6aa2e94d to your computer and use it in GitHub Desktop.
hexo-util highlight benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var highlight = require('highlight.js'); | |
var Highlights = require('highlights'); | |
var highlighter = new Highlights(); | |
var util = require('../lib'); | |
var fs = require('fs'); | |
var pathFn = require('path'); | |
var fixture = fs.readFileSync(pathFn.join(__dirname, 'fixtures', 'q3.js'), 'utf8'); | |
// Run util.highlight to load highlight.js | |
util.highlight(''); | |
module.exports = { | |
name: 'Highlight', | |
tests: [ | |
{ | |
name: 'highlight.js - auto detect', | |
fn: function(){ | |
highlight.highlightAuto(fixture); | |
} | |
}, | |
{ | |
name: 'highlight.js - language set', | |
fn: function(){ | |
highlight.highlight('js', fixture); | |
} | |
}, | |
{ | |
name: 'util.highlight - auto detect', | |
fn: function(){ | |
util.highlight(fixture); | |
} | |
}, | |
{ | |
name: 'util.highlight - language set', | |
fn: function(){ | |
util.highlight(fixture, {lang: 'js'}); | |
} | |
}, | |
{ | |
name: "highlights", | |
fn: function(){ | |
highlighter.highlightSync({ | |
fileContents: fixture, | |
scopeName: 'q3.js' | |
}); | |
} | |
} | |
] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input = ''; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function(chunk) { | |
input += chunk; | |
}); | |
process.stdin.on('end', function() { | |
var lines = input.split('\n'); | |
var meta = lines.shift().split(' '); | |
var T = meta[0] | 0; | |
var N = meta[1] | 0; | |
var M = 0; | |
var sum = 0; | |
var max = Number.MIN_VALUE; | |
for (var i = 0; i < N; i++) { | |
M = lines[i] | 0; | |
sum += M; | |
if (i >= T) { | |
sum -= lines[i - T] | 0; | |
} | |
if (sum > max) max = sum; | |
} | |
console.log(max); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment