Skip to content

Instantly share code, notes, and snippets.

@trevnorris
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevnorris/86a75c6bdc85d2eee9c1 to your computer and use it in GitHub Desktop.
Save trevnorris/86a75c6bdc85d2eee9c1 to your computer and use it in GitHub Desktop.
(do not delete) Snippets for performance workshops
/**
 * Ordered fastest to slowest.
 * Different ways to extract data from a Buffer in C++.
 */

void RunMe(const FunctionCallbackInfo<Value>& args) {
  /*
  Local<Object> buf = args[0].As<Object>();
  char* data = static_cast<char*>(buf->GetIndexedPropertiesExternalArrayData());
  size_t len = buf->GetIndexedPropertiesExternalArrayDataLength();
  */

  /*
  Local<Object> buf = args[0].As<Object>();
  char* data = node::Buffer::Data(buf);
  size_t len = node::Buffer::Length(buf);
  */

  /*
  char* data = node::Buffer::Data(args[0]);
  size_t len = node::Buffer::Length(args[0]);
  */

  /*
  HandleScope scope(args.GetIsolate());
  Local<Object> buf = args[0]->ToObject();
  char* data = node::Buffer::Data(buf);
  size_t len = node::Buffer::Length(buf);
  */

  for (size_t i = 0; i < len; i++) {
    data[i] = 0;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment