49
JavaScript. High Performance Applications 21/03/12 Dev-Pro. net 1

Js tacktalk team dev js testing performance

  • Upload
    -

  • View
    312

  • Download
    0

Embed Size (px)

DESCRIPTION

JavaScript, js, jasmin, YUI testing

Citation preview

Page 1: Js tacktalk team dev js testing performance

1

JavaScript. High Performance Applications

21/03/12Dev-Pro. net

Page 2: Js tacktalk team dev js testing performance

2

Javascript. What is it?

• Everything is a object• Class free• Typeless syntax• No compilation• C-like syntax

Page 3: Js tacktalk team dev js testing performance

3

Patterns

General solution to a commonly occurring problem. Optimal

solution to common problem

Page 4: Js tacktalk team dev js testing performance

4

Live design patterns demonstration:

• Singleton• Module• Prototype• Factory• Decorator

Page 5: Js tacktalk team dev js testing performance

5

for loop research

Page 6: Js tacktalk team dev js testing performance

6

Local Storage performance

<script>localStorage.clear();

for(var i = 0; i < 100; i++) localStorage.setItem(i, 'Value ' + i);</script>

Page 7: Js tacktalk team dev js testing performance

7

Jquery VS yourself code

Page 8: Js tacktalk team dev js testing performance

8

Jquery VS yourself code

Page 9: Js tacktalk team dev js testing performance

9

Node Storage

Page 10: Js tacktalk team dev js testing performance

10

Node Storage

Page 11: Js tacktalk team dev js testing performance

11

Regular expressions<div id="foo" class="a foo bar"></div><script> Benchmark.prototype.setup = function() { var r; var element = document.getElementById('foo'); var reContains = /(?:^| )foo(?: |$)/; function dynamicRegExp(node) { return RegExp('(?:^| )foo(?: |$)').test(node.className); } function inlineRegExp(node) { return /(?:^| )foo(?: |$)/.test(node.className); } function storedRegExp(node) { return reContains.test(node.className); } function stringIndexOf(node) { return (' ' + node.className + ' ').indexOf(' foo ') > -1; } };</script>

Page 12: Js tacktalk team dev js testing performance

12

Regular expressions

Page 13: Js tacktalk team dev js testing performance

13

prototype chain lookup, cached or not

<script> if (!Object.create) { Object.create = function(o) { function F() {} F.prototype = o; return new F(); };} var foo = { fun: "weee!" }, bar = Object.create(foo), baz = Object.create(bar), _fun = baz.fun, res;</script>

Page 14: Js tacktalk team dev js testing performance

14

prototype chain lookup, cached or not

Page 15: Js tacktalk team dev js testing performance

15

Operations which require an implicit primitive-to-object cast/conversion will be slower.

Page 16: Js tacktalk team dev js testing performance

16

Operations which require an implicit primitive-to-

object cast/conversion will be slower.

Page 17: Js tacktalk team dev js testing performance

17

undefined void 0 perf

<script>var undefined;</script><script> Benchmark.prototype.setup = function() { var r; var u; var u2; var useVoid = function(a) { return (a === void 0); }; var useGlobalUndefined = function(a) { return (a === undefined); }; var useLocalUndefined = function(a) { return (a === u2); }; var useTypeOfUndefined = function(a) { return typeof a === 'undefined'; }; };</script>

Page 18: Js tacktalk team dev js testing performance

18

undefined void 0 perf

Page 19: Js tacktalk team dev js testing performance

19

Switch vs If

Page 20: Js tacktalk team dev js testing performance

20

JavaScript Unit testing

Jasmine is a behavior-driven development framework for testing your JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.

Page 21: Js tacktalk team dev js testing performance

21

Jasmine

describe("isLeapYear", function() { it("2004 should be leap year", function() { expect(isLeapYear(2004)).toBeTruthy(); expect(isLeapYear(2004)).toEqual(true);

});

Page 22: Js tacktalk team dev js testing performance

22

Jasmine Matchers

Page 23: Js tacktalk team dev js testing performance

23

JS-test Driver

Page 24: Js tacktalk team dev js testing performance

24

JS-test Driver

Page 25: Js tacktalk team dev js testing performance

25

JS test driver

Page 26: Js tacktalk team dev js testing performance

26

YUI test framework

Page 27: Js tacktalk team dev js testing performance

27

YUI test framework. Examples

Page 28: Js tacktalk team dev js testing performance

28

BUILDINGNATIVE APPS WITH

Titanium Mobile

Page 29: Js tacktalk team dev js testing performance

29

What if you could createapps using JavaScript?

Page 30: Js tacktalk team dev js testing performance

30

Titanium Mobile

Page 31: Js tacktalk team dev js testing performance

31

Titanium MobileBuild Fully Native iPhone Apps

Page 32: Js tacktalk team dev js testing performance

32

Page 33: Js tacktalk team dev js testing performance

33

JavaScript on the the sofa

Page 34: Js tacktalk team dev js testing performance

34

Page 35: Js tacktalk team dev js testing performance

35

Page 36: Js tacktalk team dev js testing performance

36

Page 37: Js tacktalk team dev js testing performance

37

JS & Gradleassembly, minimizing, deploy

Page 38: Js tacktalk team dev js testing performance

38

Why do I need automatic assemblyand deploy?

Sooner or later any JS project grows, the amount and frequency of commitsincrease, and the solution is already outdozen JS files that need to becollect, and to minimize for the load on the server.

Page 39: Js tacktalk team dev js testing performance

39

What is a Gradle?

System assemblywhich triesto combineall the advantages of Ant,Maven, Ivy, andpresent whatcome out with Groovy.

Page 40: Js tacktalk team dev js testing performance

40

I have a plan!

1. Briefly about install Gradle2. Creating a build - a script that:

● connect the selected files and JS minimize them with Closure Compiler;

● flood min version of the FTP;● Check the script on the practice;

Page 41: Js tacktalk team dev js testing performance

41

How to install?1. Downloading a fresh package

http://gradle.org/downloads2. Unpack the disk and addsubdirectory bin in path

3. Check the installation by entering gradle tothe console

Page 42: Js tacktalk team dev js testing performance

42

JS plug-in for Gradle

There exists an Gradle two plug-in, both based for GCC, but differ in the rules of the assembly:

https://launchpad.net/gradle-jslihttps://github.com/eriwen/gradle-js-plugin

Page 43: Js tacktalk team dev js testing performance

43

Writing gradle script

In the root folder, create a new projectfile and call it core.gradle

It is assumed that the working directory script($ {projectDir}) is a subfolder SRP

Page 44: Js tacktalk team dev js testing performance

44

Check the availability of plug-in set out in the Maven repository If there is nobuildscript {

repositories {mavenCentral()

}dependencies {//Install plugin from Maven Repo

classpath 'com.eriwen:gradle-js-plugin:0.3'}

}

apply plugin: 'js'

And use it

Page 45: Js tacktalk team dev js testing performance

45

Task plug-in bonding,inputs and outputs asking

combineJs {file1 = fileTree(dir: "${projectDir}/src/Core",includes: ['Framework/core.js'])file2 = fileTree(dir: "${projectDir}/src/Core",includes: ['Framework/strings.js'])inputs.files file1 + file2outputs.file file("${projectDir}/min/corecombined.js")

}

Page 46: Js tacktalk team dev js testing performance

46

Plug-in task minification

minifyJs { inputs.files fileTree(dir: "${projectDir}/min", include: "corecombined.js") outputs.file file("${projectDir}/min/core.min.js")}

Page 47: Js tacktalk team dev js testing performance

47

To use the Ant deploy TASK, whichdescribe in a separate file - deploycore.xml.

Content you might deploycore.xmlview / copy of the articlespixelscommander.com

In gradle script call Ant TASK:

Upload to FTP

ant.importBuild 'deploycore.xml'

Page 48: Js tacktalk team dev js testing performance

48

Finally, call the script gradlefrom the console

gradle -b= core.gradle combineJs minifyJs

Questions?

Page 49: Js tacktalk team dev js testing performance

49

Thank you for your attention!

Presenter: Zakharchenko Artem