Javascript .toUpperCase() vs .toLowerCase() (v7)

Revision 7 of this benchmark created on


Description

Test actual strings that might be used for filtering

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var states = [
      "Alabama",
      "Alaska",
      "Arizona",
      "Arkansas",
      "California",
      "Colorado",
      "Connecticut",
      "Delaware",
      "Florida",
      "Georgia",
      "Hawaii",
      "Idaho",
      "Illinois",
      "Indiana",
      "Iowa",
      "Kansas",
      "Kentucky",
      "Louisiana",
      "Maine",
      "Maryland",
      "Massachusetts",
      "Michigan",
      "Minnesota",
      "Mississippi",
      "Missouri",
      "Montana",
      "Nebraska",
      "Nevada",
      "New Hampshire",
      "New Jersey",
      "New Mexico",
      "New York",
      "North Carolina",
      "North Dakota",
      "Ohio",
      "Oklahoma",
      "Oregon",
      "Pennsylvania",
      "Rhode Island",
      "South Carolina",
      "South Dakota",
      "Tennessee",
      "Texas",
      "Utah",
      "Vermont",
      "Virginia",
      "Washington",
      "West Virginia",
      "Wisconsin",
      "Wyoming"
    ];
    var result = false;

Test runner

Ready to run.

Testing in
TestOps/sec
lower to lower
$.each(['alabama', 'missouri', 'wyoming'], function(searchIndex, searchValue) {
  $.each(states, function(index, value) {
    if (!result && value.toLowerCase().equals(searchValue.toLowerCase())) {
      result = index;
      return false;
    }
  });
});
ready
lower to upper
$.each(['alabama', 'missouri', 'wyoming'], function(searchIndex, searchValue) {
  $.each(states, function(index, value) {
    if (!result && value.toUpperCase().equals(searchValue.toUpperCase())) {
      result = index;
      return false;
    }
  });
});
ready
mixed to lower
$.each(['Alabama', 'Missouri', 'Wyoming'], function(searchIndex, searchValue) {
  $.each(states, function(index, value) {
    if (!result && value.toLowerCase().equals(searchValue.toLowerCase())) {
      result = index;
      return false;
    }
  });
});
ready
mixed to upper
$.each(['Alabama', 'Missouri', 'Wyoming'], function(searchIndex, searchValue) {
  $.each(states, function(index, value) {
    if (!result && value.toUpperCase().equals(searchValue.toUpperCase())) {
      result = index;
      return false;
    }
  });
});
ready

Revisions

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