-1

I am working on a jQuery/Javascript app where performance is really important.

What would be the fastest way in getting a number value from the following code? Is the same execution time for each cases or does it matter?

//Case 1
var number = $("#someID").css("left").slice(0, -2)/100; // Returns a number

//Case 2
var number= new String($("#someID").css("left").slice(0, -2)/100); // Returns a number

//Case 3
var number = $("#someID").css("left").slice(0, -2)/100;
var number = new String(number); // Returns a number
4
  • If you're doing this over and over again, it might be a good idea to do something completely different: keep the current "left" value for each object in a separate map. Then you don't have to slice it out of the string every time you need it. Commented Jul 21, 2010 at 19:51
  • 2
    If you need performance, don’t use jQuery but plain JavaScript: document.getElementById("someID").style.left.slice(0, -2)/100 Commented Jul 21, 2010 at 19:53
  • This is in a loop. Each time something is dragged the script will take that element left value and do several calculations with it. How can I put it in a map? Commented Jul 21, 2010 at 19:53
  • Oh well if there's some other code controlling "left" value then that might not work so well. Commented Jul 21, 2010 at 20:05

1 Answer 1

0

Use the profiling functionality of Firebug to find the hotspots, and which solution is the fastest.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.