Skip to content

Commit 638a65d

Browse files
authored
Merge pull request #5 from kristerkari/feature/cleanup-perf-test-suite
Cleanup perf tests
2 parents 8443e02 + 733c35f commit 638a65d

File tree

5 files changed

+290
-235
lines changed

5 files changed

+290
-235
lines changed

benchmark.js

Lines changed: 269 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
var Benchmark = require("benchmark");
2-
var suite = new Benchmark.Suite();
3-
var suite2 = new Benchmark.Suite();
2+
var once = new Benchmark.Suite();
3+
var eightTimesTheSame = new Benchmark.Suite();
4+
var eightTimesTheSameRequire = new Benchmark.Suite();
5+
var fourTimes = new Benchmark.Suite();
6+
var eightTimes = new Benchmark.Suite();
7+
var onceRequire = new Benchmark.Suite();
8+
var fourTimesRequire = new Benchmark.Suite();
9+
var eightTimesRequire = new Benchmark.Suite();
410

5-
var current = require("./dist/perf-tests/current").process;
6-
var memoized = require("./dist/perf-tests/memoized").process;
7-
var optimized = require("./dist/perf-tests/optimized").process;
8-
var parsed = require("./dist/perf-tests/parsed").process;
11+
var process = require("./dist/perf-tests/current").process;
912

1013
var styles = {
1114
__mediaQueries: {
@@ -616,65 +619,284 @@ var Platform = {
616619
OS: "ios"
617620
};
618621

619-
suite
620-
.add("current", function() {
621-
current(styles, portrait, Platform);
622+
console.log("-----------------------------------------");
623+
624+
once
625+
.add("1 call", function() {
626+
process(styles, portrait, Platform);
627+
})
628+
.add("1 call (return early)", function() {
629+
process(stylesWithoutMediaQueries, portrait, Platform);
630+
})
631+
.on("cycle", function(event) {
632+
console.log(String(event.target));
633+
})
634+
.on("complete", function() {
635+
console.log("Fastest is " + this.filter("fastest").map("name"));
636+
console.log("-----------------------------------------");
637+
})
638+
.run({ async: false });
639+
640+
onceRequire
641+
.add("1 call (require)", function() {
642+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
643+
})
644+
.add("1 call (require, return early)", function() {
645+
require("./dist/perf-tests/current").process(
646+
stylesWithoutMediaQueries,
647+
portrait,
648+
Platform
649+
);
650+
})
651+
.on("cycle", function(event) {
652+
console.log(String(event.target));
622653
})
623-
.add("memoized", function() {
624-
memoized(styles, portrait, Platform);
654+
.on("complete", function() {
655+
console.log("Fastest is " + this.filter("fastest").map("name"));
656+
console.log("-----------------------------------------");
625657
})
626-
.add("optimized", function() {
627-
optimized(styles, portrait, Platform);
658+
.run({ async: false });
659+
660+
fourTimes
661+
.add("4 calls (orientation change)", function() {
662+
process(styles, portrait, Platform);
663+
process(styles, landscape, Platform);
664+
process(styles, portrait, Platform);
665+
process(styles, landscape, Platform);
628666
})
629-
.add("already parsed queries", function() {
630-
parsed(styles, portrait, Platform);
667+
.add("4 calls (orientation change, return early)", function() {
668+
process(stylesWithoutMediaQueries, portrait, Platform);
669+
process(stylesWithoutMediaQueries, landscape, Platform);
670+
process(stylesWithoutMediaQueries, portrait, Platform);
671+
process(stylesWithoutMediaQueries, landscape, Platform);
631672
})
632-
.add("already parsed queries, return early", function() {
633-
parsed(stylesWithoutMediaQueries, portrait, Platform);
673+
.on("cycle", function(event) {
674+
console.log(String(event.target));
675+
})
676+
.on("complete", function() {
677+
console.log("Fastest is " + this.filter("fastest").map("name"));
678+
console.log("-----------------------------------------");
679+
})
680+
.run({ async: false });
681+
682+
fourTimesRequire
683+
.add("4 calls (orientation change, require)", function() {
684+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
685+
require("./dist/perf-tests/current").process(styles, landscape, Platform);
686+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
687+
require("./dist/perf-tests/current").process(styles, landscape, Platform);
688+
})
689+
.add("4 calls (orientation change, require, return early)", function() {
690+
require("./dist/perf-tests/current").process(
691+
stylesWithoutMediaQueries,
692+
portrait,
693+
Platform
694+
);
695+
require("./dist/perf-tests/current").process(
696+
stylesWithoutMediaQueries,
697+
landscape,
698+
Platform
699+
);
700+
require("./dist/perf-tests/current").process(
701+
stylesWithoutMediaQueries,
702+
portrait,
703+
Platform
704+
);
705+
require("./dist/perf-tests/current").process(
706+
stylesWithoutMediaQueries,
707+
landscape,
708+
Platform
709+
);
634710
})
635711
.on("cycle", function(event) {
636712
console.log(String(event.target));
637713
})
638714
.on("complete", function() {
639715
console.log("Fastest is " + this.filter("fastest").map("name"));
716+
console.log("-----------------------------------------");
640717
})
641718
.run({ async: false });
642719

643-
suite2
644-
.add("orientation change: current", function() {
645-
current(styles, portrait, Platform);
646-
current(styles, landscape, Platform);
647-
current(styles, portrait, Platform);
648-
current(styles, landscape, Platform);
649-
})
650-
.add("orientation change: memoized", function() {
651-
memoized(styles, portrait, Platform);
652-
memoized(styles, landscape, Platform);
653-
memoized(styles, portrait, Platform);
654-
memoized(styles, landscape, Platform);
655-
})
656-
.add("orientation change: optimized", function() {
657-
optimized(styles, portrait, Platform);
658-
optimized(styles, landscape, Platform);
659-
optimized(styles, portrait, Platform);
660-
optimized(styles, landscape, Platform);
661-
})
662-
.add("orientation change: already parsed queries", function() {
663-
parsed(styles, portrait, Platform);
664-
parsed(styles, landscape, Platform);
665-
parsed(styles, portrait, Platform);
666-
parsed(styles, landscape, Platform);
667-
})
668-
.add("orientation change: already parsed queries, return early", function() {
669-
parsed(stylesWithoutMediaQueries, portrait, Platform);
670-
parsed(stylesWithoutMediaQueries, landscape, Platform);
671-
parsed(stylesWithoutMediaQueries, portrait, Platform);
672-
parsed(stylesWithoutMediaQueries, landscape, Platform);
720+
eightTimesTheSame
721+
.add("8 calls (the same parameters)", function() {
722+
process(styles, portrait, Platform);
723+
process(styles, portrait, Platform);
724+
process(styles, portrait, Platform);
725+
process(styles, portrait, Platform);
726+
process(styles, portrait, Platform);
727+
process(styles, portrait, Platform);
728+
process(styles, portrait, Platform);
729+
process(styles, portrait, Platform);
730+
})
731+
.add("8 calls (the same parameters, return early)", function() {
732+
process(stylesWithoutMediaQueries, portrait, Platform);
733+
process(stylesWithoutMediaQueries, portrait, Platform);
734+
process(stylesWithoutMediaQueries, portrait, Platform);
735+
process(stylesWithoutMediaQueries, portrait, Platform);
736+
process(stylesWithoutMediaQueries, portrait, Platform);
737+
process(stylesWithoutMediaQueries, portrait, Platform);
738+
process(stylesWithoutMediaQueries, portrait, Platform);
739+
process(stylesWithoutMediaQueries, portrait, Platform);
740+
})
741+
.on("cycle", function(event) {
742+
console.log(String(event.target));
743+
})
744+
.on("complete", function() {
745+
console.log("Fastest is " + this.filter("fastest").map("name"));
746+
console.log("-----------------------------------------");
747+
})
748+
.run({ async: false });
749+
750+
eightTimesTheSameRequire
751+
.add("8 calls (the same parameters, require)", function() {
752+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
753+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
754+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
755+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
756+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
757+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
758+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
759+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
760+
})
761+
.add("8 calls (the same parameters, require, return early)", function() {
762+
require("./dist/perf-tests/current").process(
763+
stylesWithoutMediaQueries,
764+
portrait,
765+
Platform
766+
);
767+
require("./dist/perf-tests/current").process(
768+
stylesWithoutMediaQueries,
769+
portrait,
770+
Platform
771+
);
772+
require("./dist/perf-tests/current").process(
773+
stylesWithoutMediaQueries,
774+
portrait,
775+
Platform
776+
);
777+
require("./dist/perf-tests/current").process(
778+
stylesWithoutMediaQueries,
779+
portrait,
780+
Platform
781+
);
782+
require("./dist/perf-tests/current").process(
783+
stylesWithoutMediaQueries,
784+
portrait,
785+
Platform
786+
);
787+
require("./dist/perf-tests/current").process(
788+
stylesWithoutMediaQueries,
789+
portrait,
790+
Platform
791+
);
792+
require("./dist/perf-tests/current").process(
793+
stylesWithoutMediaQueries,
794+
portrait,
795+
Platform
796+
);
797+
require("./dist/perf-tests/current").process(
798+
stylesWithoutMediaQueries,
799+
portrait,
800+
Platform
801+
);
802+
})
803+
.on("cycle", function(event) {
804+
console.log(String(event.target));
805+
})
806+
.on("complete", function() {
807+
console.log("Fastest is " + this.filter("fastest").map("name"));
808+
console.log("-----------------------------------------");
809+
})
810+
.run({ async: false });
811+
812+
eightTimes
813+
.add("8 calls (orientation change)", function() {
814+
process(styles, portrait, Platform);
815+
process(styles, landscape, Platform);
816+
process(styles, portrait, Platform);
817+
process(styles, landscape, Platform);
818+
process(styles, portrait, Platform);
819+
process(styles, landscape, Platform);
820+
process(styles, portrait, Platform);
821+
process(styles, landscape, Platform);
822+
})
823+
.add("8 calls (orientation change, return early)", function() {
824+
process(stylesWithoutMediaQueries, portrait, Platform);
825+
process(stylesWithoutMediaQueries, landscape, Platform);
826+
process(stylesWithoutMediaQueries, portrait, Platform);
827+
process(stylesWithoutMediaQueries, landscape, Platform);
828+
process(stylesWithoutMediaQueries, portrait, Platform);
829+
process(stylesWithoutMediaQueries, landscape, Platform);
830+
process(stylesWithoutMediaQueries, portrait, Platform);
831+
process(stylesWithoutMediaQueries, landscape, Platform);
832+
})
833+
.on("cycle", function(event) {
834+
console.log(String(event.target));
835+
})
836+
.on("complete", function() {
837+
console.log("Fastest is " + this.filter("fastest").map("name"));
838+
console.log("-----------------------------------------");
839+
})
840+
.run({ async: false });
841+
842+
eightTimesRequire
843+
.add("8 calls (orientation change, require)", function() {
844+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
845+
require("./dist/perf-tests/current").process(styles, landscape, Platform);
846+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
847+
require("./dist/perf-tests/current").process(styles, landscape, Platform);
848+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
849+
require("./dist/perf-tests/current").process(styles, landscape, Platform);
850+
require("./dist/perf-tests/current").process(styles, portrait, Platform);
851+
require("./dist/perf-tests/current").process(styles, landscape, Platform);
852+
})
853+
.add("8 calls (orientation change, require, return early)", function() {
854+
require("./dist/perf-tests/current").process(
855+
stylesWithoutMediaQueries,
856+
portrait,
857+
Platform
858+
);
859+
require("./dist/perf-tests/current").process(
860+
stylesWithoutMediaQueries,
861+
landscape,
862+
Platform
863+
);
864+
require("./dist/perf-tests/current").process(
865+
stylesWithoutMediaQueries,
866+
portrait,
867+
Platform
868+
);
869+
require("./dist/perf-tests/current").process(
870+
stylesWithoutMediaQueries,
871+
landscape,
872+
Platform
873+
);
874+
require("./dist/perf-tests/current").process(
875+
stylesWithoutMediaQueries,
876+
portrait,
877+
Platform
878+
);
879+
require("./dist/perf-tests/current").process(
880+
stylesWithoutMediaQueries,
881+
landscape,
882+
Platform
883+
);
884+
require("./dist/perf-tests/current").process(
885+
stylesWithoutMediaQueries,
886+
portrait,
887+
Platform
888+
);
889+
require("./dist/perf-tests/current").process(
890+
stylesWithoutMediaQueries,
891+
landscape,
892+
Platform
893+
);
673894
})
674895
.on("cycle", function(event) {
675896
console.log(String(event.target));
676897
})
677898
.on("complete", function() {
678899
console.log("Fastest is " + this.filter("fastest").map("name"));
900+
console.log("-----------------------------------------");
679901
})
680902
.run({ async: false });

0 commit comments

Comments
 (0)