Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3939320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:17:11+00:00 2026-05-20T00:17:11+00:00

I have this project, called Memcached.Js , which is a port of Memcached server

  • 0

I have this project, called Memcached.Js, which is a port of Memcached server to Node.js.

I’ve been playing arround with strings and buffers, comparing memory footprint and performance. For memory, there’s no question that buffer is the right choice.

But for my surprise the same is not true for performace. Performing string manipulation is faster than using buffer. This is what I tried:

// Option 1: data.toString() - amazing, but it's the best one
var commandDataStr = mdata.data.toString().substr(startPos, bytes);
var commandData = new Buffer(commandDataStr);

// Option 2: data.slice().toString() - the same as above... What?
var commandDataStr = mdata.data.slice(startPos, startPos + bytes).toString();
var commandData = new Buffer(commandDataStr);

// Option 3: data.slice() - bad
var commandData = mdata.data.slice(startPos, startPos + bytes);

// Option 4: data.copy() - bad as well
var commandData = new Buffer(bytes);
mdata.data.copy(commandData, 0, startPos, startPos + bytes);

The complete code is here:
https://github.com/dalssoft/memcached.js/blob/master/lib/memcached.ascii.commands.js#L72

Testing the code: ruby test/from_clients/perf_test.rb

The tests showed that Strings are faster than Buffer. Since it’s not what I was expecting, I think I’m probably doing something wrong, but I can’t find exactly what it is.

Can anyone help me here?

Tks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:17:11+00:00Added an answer on May 20, 2026 at 12:17 am

    Strings are built-in to V8, and allocate memory within the VM. Buffers were added not to make all string operations faster, but to represent binary data, where as Strings are unicode.

    When writing large amounts of data to a socket, it’s much more efficient to have that data in binary format, vs having to convert from unicode.

    So for common operations, like concat, I’m not surprised Strings are faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project called Data which is a data layer. In this project,
This is homework, just so that's mentioned. I have project called AdventCalendar, which is
Let's say I have a model class called Project, but instead of this: class
I'm trying to work this out. In my project, i have a file called
I have a .Net project called: Whatever.Web.UI: I use this project to put all
I have a Wpf application project called WpfTest which references WpfTestLib (A class library).
Suppose I have a free function called InitFoo . I'd like to protect this
I have this project that it's due in a few hours and I still
So I have this project in PHP where I have some include files next
Okay so, I have this project structure: package A.B class SuperClass (this class is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.