• Home
  • A Propos
  • Greasemonkey
  • HowTo GitHub
  • Performance JavaScript
  • SharepointPlus

18

Nov

Performance JavaScript

Posté par Aymeric  le dimanche 18 novembre 2012 Publié dans Kodono

Ci-dessous quelques tests de performance en JavaScript afin de voir quelles pratiques sont les plus rapides. A noter que les différences d’exécution sont parfois quasi-imperceptibles, mais peuvent avoir une certaine incidence si vous devez répéter une opération de très nombreuses fois.

1) Il est plus rapide d’utiliser === quand on compare un boolean ou un number avec «  ». En effet la comparaison avec null, 0, true, false ou un string se fait avec une conversion implicite (le test sur jspref.com) :

var test = true;
if (myvar === true) {} // plus rapide

2) Pour convertir une string en chiffre il est plus rapide d’utiliser 1*string (test sur sperf.com) :

var test="2";
console.log(1*test + 3); // plus rapide
console.log(parseInt(test) + 3); // plus lent

3) Assigner la valeur à un tableau directement plutôt qu’utiliser Array.push (test sur jsperf.com) :

// plus lent
for (i = 0; i < len; i++) itemsCopy.push(items[i])

// plus rapide
for (i = 0; i < len; i++) itemsCopy[i] = items[i]

4) Utiliser String.indexOf lorsque vous voulez savoir si une sous-chaine appartient à une plus grande chaine (test sur jsperf.com) :

if ("this is a test perf".indexOf("perf") > -1) {} // plus rapide

5) Traiter un tableau par la fin (test sur jsperf.com) :

for (var i=arr.length; i--;) {} // plus rapide

for (var i=0,len=arr.length; i<len; i++) {} // légèrement plus lent

6) Avec jQuery il est beaucoup plus rapide d’utiliser .find() que d’insérer le sous sélecteur dans le sélecteur principal (test sur jsperf.com) :

$('#mynode').find('div'); // plus rapide
$('#mynode div'); // plus lent

Me Suivre

Suivre @aymkdn

Catégories

  • À bookmarker
  • Android
  • Application
  • Astuce
  • Debug
  • Divers
  • English
  • Français
  • Images
  • Linux
  • MacOS
  • Navigateur
  • Niveau débutant
  • Niveau expert
  • Niveau intermédiaire
  • Partage
  • Performance
  • Programmation
  • Sécurité
  • Téléphonie
  • Vidéo
  • Web Design
  • Windows

Étiquettes

android Anglais Application Astuce astuces css debian Debug Divers email english facebook firefox Français github IE Images internet explorer javascript jquery Linux mysql Navigateur Niveau débutant Niveau expert Niveau intermédiaire Nokia Partage Performance php Programmation regexp sharepoint Sharepoint 2013 sharepointplus Sécurité traitement vidéo téléphone Téléphonie vidéo Web Design wifi Windows wordpress À bookmarker

Méta

  • Flux RSS
  • Administration

Recent Entries

  • Connect to SharePoint Online using an app clientId and clientSecret
  • Mount a SMB Network Drive with Pivotal Cloud Foundry (pcf) and access it using NodeJS
  • spfx error: No development certificate found. Generate a new certificate manually, or set the `canGenerateNewCertificate` parameter to `true` when calling `ensureCertificateAsync`
  • Deploy a PCF NodeJS app as a scheduled task
  • Power Automate: execute a SQL Query via On-Promise Gateway
  • Pass an URL parameter to a SharePoint Online form’s field
  • Transfer an Alexa AWS Lambda function from the online editor to the ASK CLI
  • Detect mobile in JavaScript
  • Add a domain to a Let’s Encrypt certificate
  • Get email address from a Azure DevOps « by » field in Power Apps Flow

Recent Comments

  • towkneed in Check permissions in Sharepoint based on a PermMas…
  • L in Mise à jour d’un serveur Kimsufi (OVH) depuis D…
  • Aymeric in Utiliser un email alias avec GMail [Astuce]
  • Chris in Utiliser un email alias avec GMail [Astuce]
  • alex91 in Create a self-signed certificate for localhost tes…
  • Coolwriter in Bien configurer eMule [Astuces]
  • Nico in Bien configurer eMule [Astuces]
  • Jim1988 in Permettre le retour en arrière sur une page PHP a…
  • rikimaru11273 in Bien configurer eMule [Astuces]
  • Aymeric in Execute an action before saving a form but after t…
  • Random Selection of Posts

    • Content Security Policy (CSP) blocks scripts from Violentmonkey / Greasemonkey
    • Debug a third party Android APK
    • Nokia ouvre son store d’applications [Nokia]
    • Problem with the People Picker of Sharepoint
    • Gérer les évènements touch sur mobile [JavaScript]
    • Convertir des ’em’ en ‘px’ (WebDesign)
    • Android 5.1.1 system rw Operation not permitted
© 2008 Kodono is proudly powered by WordPress
Theme designed by Roam2Rome