How to Detect, Measures & Debug Javascript strain on CPU? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
This question is pretty simple:
How does one go about detecting and debugging javascript stress on the CPU and/or optimize the code?
As you start building more and more code you reach points where things slow down. How do you figure out if you have unnecessary js running, maybe redundant code, OR if it's getting too much for a computer? My computer is pretty powerful but I can't assume everyone has a monster computer.
Is there a function, program or some tools that can help with this task?
This question seems general but I really don't know how to simplify it otherwise.
Any help or pointing in the right direction is much apprecitated :) Thank you.

Try this app called Spy-JS.
It is a tool which allows you to trace your code, and figure out which executions are taking the longest, allowing you to figure out where you need to optimize.

The tool you are searching for is called a "profiler".
The Firebug extension for Firefox comes with such a profiler and allows you to measure which parts of your Javascript code take how much time to execute.
Keep in mind that it only measures the execution speed in Firefox. Other browsers might implement certain javascript features more or less efficient, which means that the performance bottlenecks could be in other places when your application is executed in another browser. But more often than not your own code is at fault when a program runs slower than it should.

Related

Is there any memory issue to use of static in react native? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to use static in my react-native project. I am not sure about memory uses
so it will take extra memory or any memory leakage will happen in my project.
Not exactly a memory issue but as with all code elements, more lines of code (especially heavy ones) will lead to slightly more RAM usage. This isn't an issue, especially if you're using something like expo or p5.js where the online editor uses resources from the server and not your home computer. More RAM is good to have, especially with multitasking, but it's not exactly a necessity. If you have 8-12GB RAM or more, you should be fine with coding projects like these even when hosting from a laptop.
There's probably little to no memory leak risk, but that's the same with everything right, every project has that risk but it mostly works out fine. You should be good and if not, just try optimising your code. One method that I always use is splitting complex statements into simpler ones which work the same. It increases the lines of code but makes it easier to debug. Then I revert it back to the original having found the bug and fix it.
Good luck!

Messy javascript as long as it works, does it matter? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a question regarding the act of breaking the laws of javascript (Don't repeat code, etc) and that is, does it really matter as long as the performance and functionality isn't affected in anyway?
I have a script with 200+ line of code that looks messy after I did some work arounds, made it compatible with every browser and bugtested it a few times, and even after that it still runs pretty great even if the code isn't as organized. I haven't run into any errors with it yet and the load time is supreme. I should also note that I learned javascript a few weeks ago, so I am not perfect at it.
I do understand that if you're writing a huge applicaton it may have a noticeable impact on the performance and load time.
This has been on my mind for a few days and I just wanted to see your opinion about it, so please post a detailed opinion and maybe some tips and tricks as your answer. Thank you. :)
Yes, it matters. A lot.
You cite performance and download time as if they were the most important things.
I'd say that readable code that's easily understood by others might be more important than your measures.
Keeping code DRY, organized, neat, and readable are the signs of a professional in my view. Sloppy, copy & paste messes come from hacks.

javascript guidance re arranging functions into files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Have written a large system in ColdFusion/Javascript/MySQL. There is lots of Javascript. The few functions which are long are separated into cases. Currently I have all the js in 3 files, depending on the section of the application to which they refer.
Every now and again, some function which tested okay before turns out not to be working (I might have changed something elsewhere to cause that problem, without realizing I had to retest).
Okay, I deserve that, but when one js function in the file stops working, sometimes others do as well. So unexpectedly something I was counting on to validate things, or prevent a submit in the presence of errors does not work.
I've thought of breaking up the js so that any javascript function which is used by just one program will be resident there, and I would use the files with several js functions only for those that several programs have to access. That would insulate my functions somewhat from problems occurring elsewhere.
Is this approach recommended? Could someone offer good reasons for or against it? Or is there a way to "firewall" my functions so that problems with one do not spill over into another?
I'm feeling that the js is a weak link in my system -- that I can't trust it; yet I need it, so I have to find a way to make things more stable. Any and all suggestions to help would be much appreciated.
The suggestion "get better at Javascript" has already occurred to me. I am trying. Meanwhile, my needs are not very demanding. All my functions do simple things and are written in a pretty straightforward way. Yet I am having all this trouble.

Prerequisites for Creating Chrome/Safari Extensions [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have been a programmer for a long time now but have majorly operated in C and Fortran. I like to believe I am good at scientific/numerical computing.
Recently, I had an idea for a browser extension. I did some googling and realized that Javascript is my best option to do so. I have never in my life looked at HTML or Javascript or CSS. The Safari and Chrome websites suggest that I should learn HTML, CSS and Javascript.
My question was- how should I proceed with this goal in mind. I don't plan to make web applications anytime but want to concentrate only on browser extensions. How much of HTML and CSS do I really need to know? Will the Web Fundamentals at CodeAcademy suffice? Do I need to get that out of the way before attempting to study Javascript? How should I plan this study?
P.S. I looked at a few books on Javascript and it looks eerily close to C which is a big plus for me. Learning Javascript isn't my concern, learning HTML/CSS is.
The Code Academy Web Fundamentals link should suffice for the HTML & CSS. Don't be afraid of HTML- you're just marking up, or rather describing the presentation of, a document. With CSS, for the most part, you're just declaring styles on the document: Make this paragraph bold; Change this background to red, etc.
I am still learning JavaScript but I bet It'll be easier for you because of your background in C. The syntax should look very familiar. Perhaps one of the most obvious differences is that C needs a compiler to run whereas JavaScript just runs in your browser.
Some nice sandboxes to try out snippets of code are http://www.jsfiddle.net and http://www.jsbin.com.
http://www.codecademy.com/ is a great place to start.
If you want a nice technical guide to the DOM, JS, the server, and really the web in general, this is also a good guide

Good resources for handling IE7-8 specific Javascript CSS bugs [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
After a week of coding finally have my site working across all browsers and mobile devices. I made the mistake of not viewing in IE8 and IE 7 until now.
Can anyone share some steps in resolving IE7-8 compatibility issues when using jQuery and CSS?
What are some first steps to try?
If a site isn't too complex does it make sense to do server side detection and serve up an IE only site?
There should be few if any issues in jQuery - thats one of the big benefits to using jQuery or a similar library in the first place. Chances are if there is a js issue then its something you wrote as opposed to something internal to jQuery.
In both cases the bets thing to do is simply know the majority of the big things that differ in support. the Quirksmode.org compatibility tables are good for this. If you know the differences in the first place you are going to be able to create solutions up front before you ever get to testing and avoid the issues. Beyond that test cross-browser early on in the process - not at the last minute.
Depends on what problems you are running into. There are a lot of resources, such as PositionIsEverything or HasLayout, on the web complaining about & explaining different IE bugs (peekaboo, double margin etc).
It is useful to use a tool such as IETester to see your page on actual IE versions.

Categories