begin process at 2012 02 14 08:09:38
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > CHRONOMÈTRE MESURANT LA DURÉE D'UNE FONCTION

CHRONOMÈTRE MESURANT LA DURÉE D'UNE FONCTION


 Information sur la source

Note :
1 / 10 - par 1 personne
1,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Divers Classé sous :compteur, stopwatch, analyse, temps, timer Niveau :Initié Date de création :23/10/2006 Date de mise à jour :23/10/2006 14:02:09 Vu / téléchargé :10 441 / 168

Auteur : jesusonline

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


 Description

Cette classe est un chronomètre qui vous permet de mesurer le temps que prend votre code. J'ai fait cette classe en me basant sur le framework Atlas.

Il y a une classe StopWatch qui est la base du chronomètre, vous n'avez pas à utiliser directement cette classe ! La seconde classe est un singleton, vous n'avez pas besoin de l'instancier pour l'utiliser.

Le fonctionnement est simple, avant de rentrer dans le code, vous démarrer un nouveau StopWatch, executer votre code et stopper le StopWatch.

Cyril.Debug.Analyzers.start('Test1');
// Le code a executé
Cyril.Debug.Analyzers.stop('Test1');

Une popup vous affichera le temps passer pour chacun des compteurs courant. Vous avez aussi les méthodes pause et resume qui font ce que le nom indique :-)

Source

  • Type.registerNamespace('Cyril.Debug');
  • Cyril.Debug.StopWatch = function(name, description){
  • /// <summary>This class can mesure the time take by some line of code. You dont't have to manipulate this object directly, use the Cyril.Debug.Analyzers type.</summary>
  • /// <param name="name" type="String" mayBeNull="false">Name of this StopWatch.</param>
  • /// <param name="description" type="String" optional="true" mayBeNull="true">Description of this StopWatch.</param>
  • /// <returns type="StopWatch"></returns>
  • var e = Function._validateParams(arguments, [
  • {name: 'name', type: String},
  • {name: 'description', type: String, mayBeNull: true, optional:true}
  • ]);
  • if (e) throw e;
  • /* Private fields */
  • this._name = name;
  • this._description = description || '';
  • }
  • Cyril.Debug.StopWatch.prototype = {
  • /* Private fields" */
  • _startDate : null,
  • _endDate : null,
  • /* Public accesssors */
  • get_name : function(){
  • return this._name;
  • },
  • get_description : function(){
  • return this._description;
  • },
  • set_description : function(description){
  • this._description = description;
  • },
  • _elapsedTime : 0,
  • get_elapsedTime : function(){
  • return this._elapsedTime;
  • },
  • _isStarted : false,
  • get_isStarted : function(){
  • return this._isStarted;
  • },
  • _isRunning : false,
  • get_isRunning : function(){
  • return this._isRunning;
  • },
  • _isStopped : false,
  • get_isStopped : function() {
  • return this._isStopped;
  • },
  • /* Public Methods */
  • start : function(){
  • this._isStarted = true;
  • this._isRunning = true;
  • this._elapsedTime = 0;
  • this._startDate = new Date();
  • },
  • pause : function(){
  • this._elapsedTime += new Date() - this._startDate;
  • this._isRunning = false;
  • },
  • resume : function(){
  • this._isStarted = true;
  • this._startDate = new Date();
  • },
  • stop : function(){
  • if(this._isRunning)
  • this._elapsedTime += new Date() - this._startDate;
  • this._isRunning = false;
  • this._isStopped = true;
  • }
  • }
  • Cyril.Debug.StopWatch.registerClass('Cyril.Debug.StopWatch', null);
  • Cyril.Debug._Analyzers = function(){
  • /// <summary></summary>
  • }
  • Cyril.Debug._Analyzers.prototype = {
  • /* Private fields */
  • _popup : null,
  • _stopWatches : {},
  • /* Public properties */
  • get_StopWatch : function(name){
  • /// <summary>Get a StopWatch objet by name.</summary>
  • /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
  • /// <returns type="StopWatch"></returns>
  • var e = Function._validateParams(arguments, [
  • {name: 'name', type: String, mayBeNull: false, optional: false},
  • {name: 'description', type: String, mayBeNull: true, optional:true}
  • ]);
  • if (e) throw e;
  • return this._stopWatches[name];
  • },
  • /* Public methods */
  • start : function(name, description){
  • /// <summary>Start a new StopWatch, if the name already existe it will be deleted.</summary>
  • /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
  • /// <param name="description" type="String" optional="true" mayBeNull="true">Description of this StopWatch.</param>
  • var e = Function._validateParams(arguments, [
  • {name: 'message', type: String, mayBeNull: false, optional: false}
  • ]);
  • if (e) throw e;
  • this._stopWatches[name] = new Cyril.Debug.StopWatch(name, description);
  • this._stopWatches[name].start();
  • },
  • pause : function(name){
  • /// <summary>Pause the associated StopWatch, use the Resume method to restart it.</summary>
  • /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
  • var e = Function._validateParams(arguments, [
  • {name: 'message', type: String, mayBeNull: false, optional: false}
  • ]);
  • if (e) throw e;
  • this._stopWatches[name].pause();
  • },
  • resume : function(name){
  • /// <summary>Resume the associated StopWatch.</summary>
  • /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
  • var e = Function._validateParams(arguments, [
  • {name: 'message', type: String, mayBeNull: false, optional: false}
  • ]);
  • if (e) throw e;
  • this._stopWatches[name].resume();
  • },
  • stop : function(name){
  • /// <summary>Stop the associated StopWatch and display the results.</summary>
  • /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
  • var e = Function._validateParams(arguments, [
  • {name: 'message', type: String, mayBeNull: false, optional: false}
  • ]);
  • if (e) throw e;
  • this._stopWatches[name].stop();
  • this.display();
  • },
  • display : function(){
  • /// <summary>Display all StopWatch in a popup.</summary>
  • if (this._popup){
  • try {
  • this._popup.close();
  • } catch (ex) {
  • }
  • }
  • this._popup = window.open('about:blank', '_blank', 'resizable=yes,scrollbars=yes,width=300, height=200');
  • if (!this._popup){
  • alert('un anti popup a bloqué la fenêtre des résultats des tests');
  • return;
  • }
  • var sb = new Sys.StringBuilder();
  • sb.append('<html><head><title>Cyril.Debug.Analyzers</title></head><body><ul>');
  • for (name in this._stopWatches){
  • sb.append(String.format('<li><strong>{0}</strong> : {1} ms', this._stopWatches[name].get_name(), this._stopWatches[name].get_elapsedTime()));
  • var description = this._stopWatches[name].get_description();
  • if (description){
  • sb.append(String.format('<br /><p>{0}</p>', description));
  • }
  • sb.append('</li>');
  • }
  • sb.append('</ul></body></html>');
  • this._popup.document.write(sb.toString());
  • }
  • }
  • Cyril.Debug._Analyzers.registerClass('Cyril.Debug._Analyzers', null);
  • Cyril.Debug.Analyzers = new Cyril.Debug._Analyzers();
Type.registerNamespace('Cyril.Debug');

Cyril.Debug.StopWatch = function(name, description){
    /// <summary>This class can mesure the time take by some line of code. You dont't have to manipulate this object directly, use the Cyril.Debug.Analyzers type.</summary>
    /// <param name="name" type="String" mayBeNull="false">Name of this StopWatch.</param>
    /// <param name="description" type="String" optional="true" mayBeNull="true">Description of this StopWatch.</param>
    /// <returns type="StopWatch"></returns>
    var e = Function._validateParams(arguments, [
        {name: 'name', type: String},
        {name: 'description', type: String, mayBeNull: true, optional:true}
    ]);
    if (e) throw e;
    
    /* Private fields */
    this._name          = name; 
    this._description   = description || '';
}
Cyril.Debug.StopWatch.prototype = {
    
    /* Private fields" */
    _startDate : null, 
    _endDate : null,
    
    /* Public accesssors */
    get_name : function(){
      return this._name;  
    },
    
    get_description : function(){
        return this._description; 
    },
    set_description : function(description){
        this._description = description; 
    },
    
    _elapsedTime : 0, 
    get_elapsedTime : function(){
        return this._elapsedTime;
    },
    
    _isStarted : false, 
    get_isStarted : function(){
        return this._isStarted; 
    },
    _isRunning : false, 
    get_isRunning : function(){
        return this._isRunning; 
    },
    _isStopped : false, 
    get_isStopped : function() {
        return this._isStopped;
    },


    /* Public Methods */
    
    start : function(){
        this._isStarted = true; 
        this._isRunning = true;
        this._elapsedTime = 0;
        this._startDate = new Date(); 
    },
    pause : function(){
        this._elapsedTime += new Date() - this._startDate;
        this._isRunning = false;
    },
    resume : function(){
        this._isStarted = true; 
        this._startDate = new Date(); 
    },
    stop : function(){
        if(this._isRunning)
            this._elapsedTime += new Date() - this._startDate;
        this._isRunning = false;
        this._isStopped = true;
    }
}
Cyril.Debug.StopWatch.registerClass('Cyril.Debug.StopWatch', null);

Cyril.Debug._Analyzers = function(){
    /// <summary></summary>
}
Cyril.Debug._Analyzers.prototype = {
    
    /* Private fields */
    _popup : null,
    _stopWatches : {},
    
    /* Public properties */
    get_StopWatch : function(name){
        /// <summary>Get a StopWatch objet by name.</summary>
        /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
        /// <returns type="StopWatch"></returns>
        var e = Function._validateParams(arguments, [
            {name: 'name', type: String, mayBeNull: false, optional: false},
            {name: 'description', type: String, mayBeNull: true, optional:true}
        ]);
        if (e) throw e;

        return this._stopWatches[name]; 
    },
    
    /* Public methods */
    
    start : function(name, description){
        /// <summary>Start a new StopWatch, if the name already existe it will be deleted.</summary>
        /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
        /// <param name="description" type="String" optional="true" mayBeNull="true">Description of this StopWatch.</param>        
        var e = Function._validateParams(arguments, [
            {name: 'message', type: String, mayBeNull: false, optional: false}
        ]);
        if (e) throw e;

        this._stopWatches[name] = new Cyril.Debug.StopWatch(name, description);
        this._stopWatches[name].start();
    },
    pause : function(name){
        /// <summary>Pause the associated StopWatch, use the Resume method to restart it.</summary>
        /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
        var e = Function._validateParams(arguments, [
            {name: 'message', type: String, mayBeNull: false, optional: false}
        ]);
        if (e) throw e;
    
        this._stopWatches[name].pause();
    },
    resume : function(name){
        /// <summary>Resume the associated StopWatch.</summary>
        /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
        var e = Function._validateParams(arguments, [
            {name: 'message', type: String, mayBeNull: false, optional: false}
        ]);
        if (e) throw e;

        this._stopWatches[name].resume();
    },
    stop : function(name){
        /// <summary>Stop the associated StopWatch and display the results.</summary>
        /// <param name="name" type="String" mayBeNull="false" optional="false">Name of the StopWatch.</param>
        var e = Function._validateParams(arguments, [
            {name: 'message', type: String, mayBeNull: false, optional: false}
        ]);
        if (e) throw e;

        this._stopWatches[name].stop();
        this.display();
    }, 
    display : function(){
        /// <summary>Display all StopWatch in a popup.</summary>
        if (this._popup){
            try {
                this._popup.close(); 
            } catch (ex) {
            }
        }
        
        this._popup = window.open('about:blank', '_blank', 'resizable=yes,scrollbars=yes,width=300, height=200');
        if (!this._popup){
            alert('un anti popup a bloqué la fenêtre des résultats des tests');
            return;
        }
        var sb = new Sys.StringBuilder(); 
        sb.append('<html><head><title>Cyril.Debug.Analyzers</title></head><body><ul>');
        for (name in this._stopWatches){
            sb.append(String.format('<li><strong>{0}</strong> : {1} ms', this._stopWatches[name].get_name(), this._stopWatches[name].get_elapsedTime()));
            var description = this._stopWatches[name].get_description();
            if (description){
                sb.append(String.format('<br /><p>{0}</p>', description));
            }
            sb.append('</li>');
        }
        sb.append('</ul></body></html>');
        this._popup.document.write(sb.toString()); 
    }    
}
Cyril.Debug._Analyzers.registerClass('Cyril.Debug._Analyzers', null);

Cyril.Debug.Analyzers = new Cyril.Debug._Analyzers();

 Conclusion

Vous trouverez dans le zip un exemple d'utilisation de ce chronomètre, pour pouvoir l'executer il vous faut la beta 1 d'Atlas (http://ajax.asp.net) et Visual Web Dev Express (gratuit : http://www.microsoft.com/france/msdn/vstudio/expre ss/vwd/telechargez.mspx)

Si vous ne voulez pas utiliser ASP.net pour tester le script il vous faudra utiliser Microsoft Ajax Library pour faire fonctionner le fichier JavaScript.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

23 octobre 2006 14:02:09 :
.

 Sources du même auteur

IMPLÉMENTATION DU TYPE GUID AVEC MICROSOFT AJAX
Source avec Zip Source avec une capture GADGET POUR VISTA : CPU GRAPH
FUNCTION.WAITFOR : ATTENDRE UNE CONDITION AVANT D'EXECUTER U...
DESORGANISÉ UN TABLEAU : LA MÉTHODE SORT
FONCTION GETELEMENTSBYCLASS

 Sources de la même categorie

COLONNES ADAPTABLES EN HAUTEUR par dronoide
Source avec Zip VECTEURS ET MATRICES: OUTILS GRAPHIQUES UTILES par william voirol
Source avec Zip Source avec une capture HTML5 PLAYER par kazma
Source avec Zip Source avec une capture SCROLLBAR PERSONNALISABLE par kazma
Source avec Zip INFO BULLE par RudiRatlos

 Sources en rapport avec celle ci

Source avec Zip TIMER : SETTIMEOUT & SETINTERVAL AMÉLIORÉS par jdmcreator
Source avec Zip CHRONOMÈTRE AMÉLIORÉ par Kolosta
Source avec Zip Source avec une capture STRIKER BASEBALL par CSIBern
Source avec Zip ANIMATION LOGO par opossum_farceur
Source avec Zip COMPTEUR DE CLICS V2 DÉTAILS SUR OBJET CLIQUÉ PLUS DATES ET ... par abdelaziz_info

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Recherche compteur donnant le temps qui c'est passer depuis une date. [ par vali103 ] Bonjour,Je recherche un compteur permettant de donner le temps à partir d'une date (en année, mois, jours, heures, minutes, et pourquoi pas secondes)e Compteur de temps restant pour acheter un produit [ par jzeel ] Bonjour a tous, J'ai un site ou je vends des articles rabais, mais l'article est disponible pour achat que pendant 48 heures... j'aimerais mettre un Compteur de temps restant Javascript [ par poinball ] Bonjour à tous ! J'ai réussi a me trouver un petit code sympa pour me faire un countdown d'évènement. Maintenant j'aimerais sortir du countdown séparé Script enchainer plusieur image en fondu compatibilité IE et Safari [ par jakado ] Bonjour j'ai le code qui suit (que j'ai trouvé sur un blog) qui marche très bien sur IE et Firefox mais pas sur Safari et Chrome je serai content si transition fond ecran éléatoire [ par tif27940 ] Bonjour, voici mon code pour l'affiche de mon fond écran aléatoire qui fonctionne très bien mais je voudrais savoir si il est possible de mettre des Mélanger les lettres d'un mot [ par Lany09 ] L'exercice en javascript consiste à mettre en place une application web capable de mélanger les lettres d'un mot. ça parait peut-être tout con mais c' Temps d'exécution [ par Bobshit75 ] Bonjour à tous, Voilà, j'ai essayé de faire de l'Ajax sans JQuery (je regrette mais bon ^^). Le problème que je rencontre c'est un problème au niveau voyage dans le temps par google [ par xentrikweb ] recherche du caractère &é sur google donne 0.00 seconde et de surcroit il pointe du javascripte sur code source.fr si cette entiter vie elle cherche u Bouger deux ScrollBar en même temps [ par BeberEberlue ] Bonjour Je cherche à faire en sorte que mes deux scrollbar horizontales bougent en même temps, c-a-d qui si l'utilisateur déplace la première scrollb afficher deux div en même temps dans deux cellules différentes d'un tableau [ par lyamcarter ] Bonjour, Je souhaite afficher plusieur div en même temps dans différente cellule de tableau. Mais cela ne fonctionne pas. pourriez vous m'apporter vot


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,903 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales