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 6715801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:39:28+00:00 2026-05-26T08:39:28+00:00

I am currently doing a big project (by big I mean, many processes) where

  • 0

I am currently doing a big project (by big I mean, many processes) where every millisecond I save means a lot (on the long run), so I want to make sure I am doing it the right way.

So, what is the best way to ensure you will have an array greater than 1?

  • a) use indexOf(), then if result is different than -1, split()
  • b) split (regardless if characters exist), then do stuff ONLY if the
    array.length is greater than 1
  • c) another not listed above
  • 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-26T08:39:29+00:00Added an answer on May 26, 2026 at 8:39 am

    Using jsPerf, it appears that omitting .indexOf() is roughly 23% more efficient that including it over 500,000 iterations (11.67 vs. 8.95 operations per second):

    Without indexOf():

    var str = "test";
    for (var i = 0; i < 500000; i++) {
        var test = str.split('.');
    }
    

    With .indexOf():

    var str = "test";
    for (var i = 0; i < 500000; i++) {
        if (str.indexOf('.')) {
            var test = str.split('.');
        } else {
            var test = str;
        }
    }
    

    http://jsperf.com/split-and-split-indexof

    EDIT

    Hmm… If the following line is:

    if (str.indexOf('.') > -1)
    

    http://jsperf.com/split-and-split-indexof-with-indexof-check

    Or any other comparison, it’s seemingly quite a bit faster (by about 69%).

    The only reason I can think this is the case is that running .split() on every variable will perform two functions on each value (find, then separate), instead of just one when necessary. Note, this last part is just a guess.

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

Sidebar

Related Questions

As I am currently doing this project in only C, I've up untill this
We're currently doing some Word automation, and want to be able to insert a
I'm currently doing a project in C# working with windows forms. During the course
I am working on a big .NET project. I am currently creating an automated
We currently have a big Maven 2 project that is rather a collection of
I'm currently doing an academic benchmark, TPC-H, and I have some big tables that
I'm currently doing some maintenance on an application and I've come across a big
I'm currently doing some GUI testing on a ASP.net 2.0 application. The RDBMS is
I'm currently doing the following to use typed datasets in vs2008: Right click on
i'm currently doing some reports for SSRS, and i just confirm what i already

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.