Script Preparation code:
x
 
function CompletedCourses() {
    
    this.init = function() {
        this._state = new Array(COURSES.length).fill(false);
    }
    this.completeCourse = function(index) {
        this._state[index] = true;
    }
    this.getCompletedCourses = function() {
        const completedCourses = COURSES.filter((course, index) => this._state[index]);
        return completedCourses;
    }   
  this.init();
    return this;
}
function CompletedCoursesBits() {
    
    
    
    this.initBits = function() {
        // using bits
        this._status = 0;
    }
    this.completeCourseBit = function(index) {
        this._status = this._status | 1 << index;
    }
    this.getCompletedCoursesByBits = function() {
        const completedCourseWithBits = COURSES.filter((course, index) => (this._status & 1 << index));
        return completedCourseWithBits;
    }
    this.initBits();
  return this;
}
function Student(name, completedCourses) {
    this.name = name;
    this.courses = completedCourses;
}
var COURSES = [
    'English',
    'Chemistry',
    'Physics',
    'Literature',
    'Arts',
    'Algabra',
    'Infi',
    'Algorithms',
    'DataStructures',
    'Complexity'
];
var n = 10000;
Tests:
  • Bitwise

     
    function startBits() {
      // create
      const students = [];
      for (let i = 0; i < n; i++) {
        students.push(new Student('Mike', new CompletedCoursesBits()));
      }
      
      for (let i = 0; i < n; i++) {
        const student = students[i];
        COURSES.forEach((course, index) => index & 1 ? student.courses.completeCourseBit(index) : '')
      }
      
      // log
      const list = [];
      
      for (let i = 0; i < n; i++) {
        const student = students[i];
        list.push(student.courses.getCompletedCoursesByBits());
      }
    }
    startBits();
  • Boolean

     
    function start(){
      // create
      const students = [];
      for (let i = 0; i < n; i++) {
        students.push(new Student('Mike', new CompletedCourses()));
      }
      
      // populate
      for (let i = 0; i < n; i++) {
        const student = students[i];
        COURSES.forEach((course, index) => index & 1 ? student.courses.completeCourse(index) : '')
      }
      
      // log
      const list = [];
      for (let i = 0; i < n; i++) {
        const student = students[i];
        list.push(student.courses.getCompletedCourses());
      }
    }
    start();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Bitwise
    Boolean

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Chrome 112 on Linux
View result in a separate tab
Test name Executions per second
Bitwise 417.1 Ops/sec
Boolean 297.8 Ops/sec