Skip to content

Instantly share code, notes, and snippets.

@agreatfool
agreatfool / messagepack_performance.js
Created April 7, 2016 06:40
Compare the performance of two javascript message pack implementation: "msgpack5" & "msgpack-lite"
"use strict";
const msgpack = require('msgpack5')();
const msgpacklite = require("msgpack-lite");
const obj = {name: "jonathan", age: 29, gender: "male"};
const count = 100000;
const try5 = (act) => {
if (act === "encode") {
for (let i = 0; i < count; i++) {
// $ node -v
// v8.4.0
// node --max-old-space-size=8192
"use strict";
var v8 = require("v8");
console.log(v8.getHeapStatistics());
// { total_heap_size: 9437184,
// total_heap_size_executable: 3145728,
// $ node -v
// v8.4.0
"use strict";
var v8 = require("v8");
console.log(v8.getHeapStatistics());
// { total_heap_size: 9437184,
// total_heap_size_executable: 3145728,
// total_physical_size: 6928200,
#!/usr/bin/env node
// $ node -v
// v8.4.0
/**
Debug输出信息的查看,使用:
DEBUG=MEM:* node xxx.js
查看内存输出日志:
DEBUG=MEM:ReportMemory node ...
$ node --expose-gc --trace-gc --trace-gc-verbose ./cases/leak-and-gc.js --normal
[44972:0x103000000] Fast promotion mode: false survival rate: 57%
[44972:0x103000000] 60 ms: Scavenge 3.0 (5.5) -> 2.7 (6.5) MB, 1.2 / 0.0 ms allocation failure
[44972:0x103000000] Memory allocator, used: 6656 KB, available: 1459712 KB
[44972:0x103000000] New space, used: 581 KB, available: 425 KB, committed: 2048 KB
[44972:0x103000000] Old space, used: 778 KB, available: 0 KB, committed: 1024 KB
[44972:0x103000000] Code space, used: 1180 KB, available: 1 KB, committed: 1536KB
[44972:0x103000000] Map space, used: 201 KB, available: 0 KB, committed: 512 KB
[44972:0x103000000] Large object space, used: 0 KB, available: 1459191 KB, committed: 0 KB
[44972:0x103000000] All spaces, used: 2741 KB, available: 1459617 KB, committed: 5120KB
#!/usr/bin/env node
// node --expose-gc --trace-gc cases/leak-and-gc.js --normal | node cases/pipe-gc-parser.js
// node --expose-gc --trace-gc-nvp cases/leak-and-gc.js --normal | node cases/pipe-gc-parser.js
"use strict";
const readline = require("readline");
const GcParser = require("v8-gc-log-parser");
@agreatfool
agreatfool / compiled.d.ts
Last active February 6, 2018 07:48
Static codes generated by protobuf.js
import * as $protobuf from "protobufjs";
/** Namespace com. */
export namespace com {
/** Namespace book. */
namespace book {
/** Properties of a Book. */
interface IBook {
@agreatfool
agreatfool / book_grpc_pb.d.ts
Created February 6, 2018 07:49
Codes generated by grpc-tools
// package: com.book
// file: book/book.proto
import * as grpc from "grpc";
import * as book_book_pb from "../book/book_pb";
interface IBookServiceService extends grpc.IMethodsMap {
getBook: IGetBook;
getBooksViaAuthor: IGetBooksViaAuthor;
getGreatestBook: IGetGreatestBook;
@agreatfool
agreatfool / book.swagger.json
Created February 6, 2018 07:59
Generated swagger.json
{
"swagger": "2.0",
"info": {
"title": "book/book.proto",
"version": "version not set"
},
"schemes": [
"http",
"https"
],
{
"name": "profile",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",