MountainWest JavaScript 2014

Cómo diseñar buenos benchmarks para aplicaciones JavaScript

Alex Navasardyan  · 

Presentación

HTML (pincha para descargar)

Vídeo

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

alright cool so i'm i'm here to talk to you guys about benchmarks and what they are and why is it interesting and kind of useful to to have them or to like sort of start writing them i guess so a little bit about me i'm alex nova saudi and to cool

and github to cool and twitter i work for a company called dockyard we are ember.js rails mobile consultancy based in boston so kind of like so benchmark is is hard especially especially when we talk about benchmarking your JavaScript code and that's because

we are working with browsers and browsers are like the actually sophisticated pieces of software because when you run your code JavaScript code it gets executed it actually executed native code which is an assembler right and then JavaScript engines they are

written in C++ I then you know there's a complexity of your JavaScript code because your JavaScript code can be really sophisticated depending on the framework they're using like ember.js or backbone or whatever right and another quirk of benchmarking

is hardware hardware is a big big problem because not a richly problem but you sort of have to be aware of that if you want to know or or reliably run benchmarks and have reliable results you better off having like it's you know server standalone server

that does nothing but just runs benchmarks so that is kind of like hard it's like a lot of moving parts and like why even bother right so giving that we're all writing JavaScript in world web developers we should be aware of that when you run your

code when you're on you go in the browser you are only just scratching the surface so you only touch on touching this one layer which javascript right so again yo code then there is a compiler and what do I mean by compiler compiler is actually not the

i would say proper term for that it's more like javascript engine compiler is a part of the javascript engine so firefox is spider monkey opera has Carrick on IE has chakra but i'm going to be specifically talking about v8 here so this yoko javascript

is being run by the compiler so compiler does something to it and then it turns on the native code so it turns out that the code that you write your JavaScript code is actually not the same code that gets executed sounds kind of bizarre right so like what

what is going on right so for that I'll talk a little bit about compilers I just sort of a compiler compilers one to one thing this is this example is called constant propagation right so we're trying to benchmark here we're trying to benchmark

converting a string to a number and there's double dildo operator if you guys are to know that's just a an equivalent of parson so we have this constant a right and we're running thousand times a loop and then we measured the time which is log

it on the console right so it's kind of like simple right so this is the code that we're working with but compiler is kind of like smart so what it does it looks at the a and says well it's a constant right so I might as well just in line it right

that cool then it looks further and it goes well it's a constant and all you do you just basic converted in constant so I might as well just perform this operation once i'm just going to convert it once and it just going to line it again and at this

point your bench marketing that assignment cool all right so let's take a look at another example so it smart developer will look at that and says you know what let's let's make a a non-constant let me use data now to string so now using constant

anymore awesome right but compiler will take a look at that and say well you know what it's all good but I'm just going to hoist out that operations of conversion out of the loop I don't have to do it like many times right so I'm just going

to create a new variable and you are benchmarking the assignment again so it's totally not what you think is going on and even that is called loop invariant code motion when things are hosted out of the loop so it's all good and then compiler looks

[ ... ]

Nota: se han omitido las otras 1.933 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.