ursus contionabundo: (Ergänzung)

Beitrag lesen

Tatsächlich!

Da hab ich wohl gesehen, was ich schreiben wollte - nicht was ich geschrieben habe. Die Optimierungen des menschlichen Hirns sind nicht unter allen Umständen optimal...

Hier mal eine Fassung ohne wahlfreien Zugriff.

var s = String('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu');
var o = new String(s);

var tStart;
var tEnd;

console.log ('String: length ist ' +  s.length );
tStart = new Date().getTime();
var l = s.length;

for ( let i=1; i < 1000; i++ ) {
	for ( let p = 0; p < l; p++ ) {
	  let a = s.replace( 'foobar', ' ' );
	}
}
tEnd = new Date().getTime();

console.log ( 'Mit String: '  + String( tEnd-tStart ) + ' Millsekunden.');

console.log ('Objekt: length ist ' +  o.length );
tStart = new Date().getTime();
for ( let i=1; i < 1000; i++ ) {
	for ( let p = 0; p < l; p++ ) {
	  let a = o.replace( 'foobar', ' ' );
	}
}
tEnd = new Date().getTime();

console.log ( 'Mit Objekt: '  + String( tEnd-tStart ) + ' Millsekunden.');

Ergebnis:

String: length ist 996
Mit String: 102 Millsekunden.
Objekt: length ist 996
Mit Objekt: 347 Millsekunden.

Du hast Recht: In diesem Test sieht das Objekt "alt" aus.

Aber eigentlich ist das auch erklärbar: Wenn der Interpreter selbst die primitiven Daten in ein ihm gut bekanntes Objekt pokt, dann braucht er hinterher nicht bei jedem Zugriff untersuchen ob das Objekt diese oder jene Eigenschaft und diese oder jene Methode hat, denn das ist ja schon bekannt. Das spart ziemlich viele "Wenn-Dann-Sonst-" oder "try-catch-Konstrukte".

0 69

Cast: String oder new String

pl
  • javascript
  1. 0
    dedlfix
    1. 0
      pl
    2. 0
      Rolf B
      1. 0
        pl
        1. 1
          dedlfix
          1. 0
            pl
            1. 0
              dedlfix
              1. 0
                pl
          2. 0
            Rolf B
            1. 0
              dedlfix
              1. 0
                Rolf B
                1. 1
                  dedlfix
                2. 0
                  1unitedpower
        2. 0
          1unitedpower
          • javascript
          • typescript
          1. 0
            pl
  2. 0
    ursus contionabundo
    1. 0
      dedlfix
      1. 0
        ursus contionabundo
    2. 0
      pl
      1. 0
        ursus contionabundo
        1. 0
          pl
          1. 0
            ursus contionabundo
            1. 0
              pl
              1. 0

                Ganz unverblümt...

                ursus contionabundo
                • meinung
                1. 0
                  pl
                  1. 0
                    ursus contionabundo
                    1. -2
                      pl
                      1. -1
                        ursus contionabundo
                        1. 0
                          Felix Riesterer
                          1. 0

                            Frage immer noch offen!

                            pl
                            1. 0
                              dedlfix
                              1. 0
                                pl
                                • javascript
                                1. 0
                                  Felix Riesterer
                                  1. 0
                                    pl
                                2. 1
                                  dedlfix
                                  1. 0
                                    pl
                                    1. 0
                                      dedlfix
                                      1. 0
                                        pl
                          2. -1
                            pl
                            1. 0
                              Felix Riesterer
                              1. -1
                                pl
                                • zu diesem forum
                                1. 0
                                  Gunnar Bittersmann
                                  • meinung
                                  1. 1
                                    dedlfix
                                    1. 0
                                      Christian Kruse
                                      1. 0
                                        dedlfix
                                        1. 0
                                          Tabellenkalk
                                          1. 0
                                            Gunnar Bittersmann
                                            • logik
                                        2. 0
                                          Gunnar Bittersmann
                                          • logik
                                          1. 0
                                            dedlfix
                                            • meinung
                                            1. 0
                                              MudGuard
                                            2. 0
                                              Gunnar Bittersmann
                                      2. 1
                                        JürgenB
                                        1. 0
                                          Felix Riesterer
                                          1. 0
                                            Gunnar Bittersmann
                                    2. 0
                                      Gunnar Bittersmann
                                      1. 0
                                        Tabellenkalk
                                        1. 0
                                          Gunnar Bittersmann
                                          1. 0
                                            Rolf B
                                    3. 0
                                      Orlok
                                      • mathematik
                                  2. 0
                                    Gunnar Bittersmann
                                    • musik
                            2. 0
                              Gunnar Bittersmann
                              • meinung
                              • zu diesem forum
                            3. 0
                              ursus contionabundo
                              1. 0

                                (Ergänzung)

                                ursus contionabundo
                                1. 0
                                  Rolf B
                                  1. 0
                                    ursus contionabundo
                                2. 0
                                  Rolf B
                                  • meinung
                                  • performance
                                  1. 0
                                    ursus contionabundo
                                    1. 0
                                      Rolf B
                                      • humor
                                      • meinung