Created
November 16, 2011 20:22
-
-
Save ry/1371250 to your computer and use it in GitHub Desktop.
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
% time ./node benchmark/fast_buffer2_creation.js | |
./node benchmark/fast_buffer2_creation.js 0.34s user 0.01s system 79% cpu 0.450 total | |
% time ./node benchmark/fast_buffer_creation.js | |
./node benchmark/fast_buffer_creation.js 0.52s user 0.02s system 97% cpu 0.549 total | |
% time ./node benchmark/buffer_creation.js | |
./node benchmark/buffer_creation.js 2.61s user 0.63s system 117% cpu 2.758 total |
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
diff --git a/src/node_buffer.cc b/src/node_buffer.cc | |
index d2335ff..0d8b3b0 100644 | |
--- a/src/node_buffer.cc | |
+++ b/src/node_buffer.cc | |
@@ -201,6 +201,7 @@ Buffer::~Buffer() { | |
Replace(NULL, 0, NULL, NULL); | |
} | |
+static char bigbuffer[10 * 1024 * 1024]; | |
void Buffer::Replace(char *data, size_t length, | |
free_callback callback, void *hint) { | |
@@ -209,7 +210,7 @@ void Buffer::Replace(char *data, size_t length, | |
if (callback_) { | |
callback_(data_, callback_hint_); | |
} else if (length_) { | |
- delete [] data_; | |
+ //delete [] data_; | |
V8::AdjustAmountOfExternalAllocatedMemory(-(sizeof(Buffer) + length_)); | |
} | |
@@ -220,7 +221,7 @@ void Buffer::Replace(char *data, size_t length, | |
if (callback_) { | |
data_ = data; | |
} else if (length_) { | |
- data_ = new char[length_]; | |
+ data_ = bigbuffer; | |
if (data) | |
memcpy(data_, data, length_); | |
V8::AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) + length_); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment