GEJS Estadistica de Vocales

JavaScript performance comparison

Test case created by

Preparation code

<script>
  var estadisticaDeVocales1 = (function () {
    var listaDeVocales = 'aeiouáéíóúàèìòùâêîôûäëïöü';
    function normalizaVocal(c) {
      var pos = listaDeVocales.indexOf(c);
      if (pos !=-1) return listaDeVocales.charAt(pos%5);
      else return false;
    }
    return function(texto) {
      texto =  texto.toLowerCase();
      var tablaDeFrecuencias = {};
      for (var j=0, len = texto.length;j<len;j++) {
        var caracter = normalizaVocal(texto.charAt(j));
        if (caracter !== false) {
          if (caracter in tablaDeFrecuencias)
             tablaDeFrecuencias[caracter]++;
          else tablaDeFrecuencias[caracter] = 1;       
         }
       }
       return tablaDeFrecuencias;
    }
  })();
  
  var estadisticaDeVocales2 = (function () {
    var listaDeVocales = 'aeiouáéíóúàèìòùâêîôûäëïöü';
    var listaDeVocalesRegEx = /[aeiouáéíóúàèìòùâêîôûäëïöü]/g;
    function normalizaVocal(c) {
      var pos = listaDeVocales.indexOf(c);
      if (pos !=-1) return listaDeVocales.charAt(pos%5);
      else return false;
    }
    return function(texto) {
      texto = texto.toLowerCase();
      var tablaDeFrecuencias = {};
      var vocalesDelTexto = texto.match(listaDeVocalesRegEx);
      if (vocalesDelTexto !== null)
      for (var j=0, len = vocalesDelTexto.length;j<len;j++) {
        var vocal =normalizaVocal(vocalesDelTexto[j]);
        if (vocal in tablaDeFrecuencias)            tablaDeFrecuencias[vocal]++;
        else tablaDeFrecuencias[vocal] = 1;       
      }
      return tablaDeFrecuencias;
    }
  })();
  
  var estadisticaDeVocales3 = (function(){
    var rxs= {'a':/[aáàâä]/g,
              'e':/[eéèêë]/g,
              'i':/[iíìîï]/g,
  	    'o':/[oóòôö]/g,
  	    'u':/[uúùûü]/g};
  
    return function (texto) {
      texto = texto.toLowerCase();
      var tablaDeFrecuencias = {};
      for (vocal in rxs) {
        var aux = texto.match(rxs[vocal]);
        if (aux !== null) tablaDeFrecuencias[vocal] = aux.length;
      }
      return tablaDeFrecuencias;
    }
  })();
  
  
  
  var count_different_vowels = function(str) {
          var vowel_counter = {};
          var a_accents = /[áãàâä]/;
          var e_accents = /[éêèë]/;
          var i_accents = /[íîìï]/;
          var o_accents = /[óõòôö]/;
          var u_accents = /[úùûü]/;
          
          var final_string = str.replace(a_accents, 'a').replace(e_accents,'e')
                  .replace(i_accents, 'i').replace(o_accents, 'o').replace(u_accents, 'u');
          
          var different_vowels = 0;
          for (var i = 0; i < final_string.length; i++) {
              if (final_string[i].match(/[aeiou]/)) {
                  if (final_string[i] in vowel_counter) {
                      vowel_counter[final_string[i]]++;
                  } else {
                      vowel_counter[final_string[i]] = 1;
                      different_vowels++;
                  }
              }
          }
          return different_vowels;
      };
  
  
  
  //TEST
  var ej =  'Había un píngüinó suélto ën lá sëlvá'
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
estadisticaDeVocales1
estadisticaDeVocales1(ej);
pending…
estadisticaDeVocales2
estadisticaDeVocales2(ej);
pending…
estadisticaDeVocales3;
estadisticaDeVocales3(ej);
pending…
count_different_vowels
count_different_vowels(ej)
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments