Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ Run #1000: 0.4652369999999948 ms
...
Run #10000: 0.4628829999999766 ms
```

### Running the renderServer test
```
$ node test/renderServer.test.js
```
### Machine Info
These tests were run using a MacBook Pro (Retina, 15-inch, Mid 2014) with 2.8 GHz Intel Core i7 processor and 16 GB 1600 MHz DDR3 of memory.

Expand Down
32 changes: 19 additions & 13 deletions ReactMicroBenchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,24 @@ var renderServer = function (comments) {
);
};

log = console.log.bind(console);
timestamp = function() { return process.hrtime()[1] / 1e6; };
module.exports = {
renderServer: renderServer
};

var comments = [];
var NUM_COMMENTS = 10;
for (var i = 0; i < NUM_COMMENTS; ++i) {
comments.push({author:"Name "+i, text:"This is comment #"+i+"."});
}
for (i = 0; i < 10000; ++i) {
var start, stop;
start = timestamp();
renderServer(comments);
stop = timestamp();
log('Run #' + (i + 1) + ':', (stop - start), 'ms');
var log = console.log.bind(console);
var timestamp = function() { return process.hrtime()[1] / 1e6; };

if (require.main === module) {
var comments = [];
var NUM_COMMENTS = 10;
for (var i = 0; i < NUM_COMMENTS; ++i) {
comments.push({author:"Name "+i, text:"This is comment #"+i+"."});
}
for (i = 0; i < 10000; ++i) {
var start, stop;
start = timestamp();
renderServer(comments);
stop = timestamp();
log('Run #' + (i + 1) + ':', (stop - start), 'ms');
}
}
13 changes: 13 additions & 0 deletions test/renderServer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const assert = require('assert');
const { renderServer } = require('../ReactMicroBenchmark');

const result = renderServer([
{ author: 'Alice', text: 'Hello' },
{ author: 'Bob', text: 'Hi there' }
]);

assert.strictEqual(typeof result, 'string', 'renderServer should return a string');
assert.ok(result.length > 0, 'renderServer result should not be empty');
assert.ok(result.includes('<div'), 'rendered markup should contain a <div> element');

console.log('renderServer test passed');