cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              $bg: #16526B;
$box: #07263B;
$moment: #61CDD5;
$native: #F04E51;

* {
  box-sizing: border-box;
}

html,
body,
#content {
  height: 100%;
}

body {
  background: $bg;
  background-image: linear-gradient(lighten($bg, 2%), darken($bg, 2%));
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: #eee;
  font-family: 'Source Sans Pro', sans-serif;
  padding: 30px;
}

.app {
  display: flex;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  max-width: 1000px;
  margin: 0 auto;
}

.generate {
  text-align: center;
  
  label {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  
  select {
    appearance: none;
    background: white url('http://www.outboundengine.com/wp-content/uploads/2016/03/icon-chevron-down-grey2.svg');
    background-position: center right 15px;
    background-size: auto 10px;
    background-repeat: no-repeat;
    border: none;
    font-size: 26px;
    padding: 10px 40px 10px 15px;
  }

  button {
    background: #218791;
    border: none;
    border-radius: 5px;
    color: white;
    cursor: pointer;
    font-size: 26px;
    margin: 0 0 0 10px;
    padding: 10px 15px;
  }
}

.bms {
  display: flex;
  justify-content: center;
  margin: 30px auto 0;
  width: 100%;
}

.bms__process {
  background: $box;
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
  border-radius: 15px;
  margin: 0 10px;
  padding: 20px 20px 25px;
  width: 26%;
}

.bms__process__title {
  font-size: 16px;
  margin: 0 auto 25px;
  text-align: center;
}

.bms__bm__graph {
  background: #0D4149;
  border-radius: 15px;
  box-shadow: 0 0 0 1px  darken(#07263B, 3%);
  padding-right: 80px;
  position: relative;
}

.bms__bm__graph__fill {
  border-radius: 15px;
  font-size: 12px;
  height: 19px;
  min-width: 20px;
  text-align: right;
  transition: width 1s ease-in-out, background 1s ease;
  width: 0%;
}

.bms__bm__graph__fill--empty {
  background: lighten(#0D4149, 5%) !important;
}

.bms__bm--moment .bms__bm__graph__fill {
  background: $moment;
}

.bms__bm--native .bms__bm__graph__fill {
  background: $native;
}

.bms__bm__graph__value {
  font-size: 12px;
  opacity: .8;
  position: absolute;
  right: 10px;
  top: 2px;
}

.bms__bm__label {
  margin: 5px 5px 10px;
}

.bms__bm__check {
  color: #37666F;
  font-size: 12px;
  margin: 20px auto 0;
  text-align: right;
}

.bms__bm__check__status {
  background: #E04149;
  border: 1px solid $box;
  box-shadow: 0 0 0 1px #E04149;
  border-radius: 50%;
  display: inline-block;
  height: 10px;
  margin: -2px 0 0 5px;
  vertical-align: middle;
  width: 10px;
}

.bms__bm__check__status--true {
  background: #25A452;
  box-shadow: 0 0 0 1px #25A452;
}
            
          
!
            
              const PROCESSES = [
  'isToday',
  'isSameMonth',
  'isWithinThirtyDays'
];
const TODAY = new Date();
const YEAR_START = new Date(TODAY.getFullYear(), 0, 1);
const YEAR_END = new Date(TODAY.getFullYear(), 11, 31);

class App extends React.Component {
  constructor () {
    super();
    
    this.state = {
      dataSet: [],
      de: [],
      tGenerate: null,
      isTodayMoment: null,
      isTodayNative: null
    };
    
    this.start = this.start.bind(this);
    this.getData = this.getData.bind(this);
    this.isToday = this.isToday.bind(this);
  }

  start () {
    const dataSet = this.getData(this.entries.value);
    this.setState({dataSet: dataSet});
  }

  getRandomDate (start = YEAR_START, end = YEAR_END) {
    return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
  }
  
  getData (entries) {
    const dataSet = [];
    const tGenerateA = performance.now();
    
    for (let i = 0; i <= entries; i++) {
      dataSet.push({
        id: i,
        date: this.getRandomDate()
      });
    }
    
    const tGenerateB = performance.now();
    
    this.setState({tGenerate: tGenerateB - tGenerateA});
    
    PROCESSES.forEach(processName => {
      this.processDataset(processName, dataSet);
      this.processDataset(processName, dataSet, false);
    });
    
    return dataSet;
  }
  
  updateState (useMoment, name, newValues) {
    const setName = useMoment ? `${name}Moment` : `${name}Native`;
    this.setState({[setName]: newValues});
  }
  
  isToday (data, useMoment, today) {
    if (useMoment) {
      const day = moment(data.date);
      return today.isSame(day, 'day');
    } else {
      const day = new Date(data.date);
      return today.getDate() === day.getDate() &&
        today.getMonth() === day.getMonth() &&
        today.getFullYear() === day.getFullYear() ? 1 : 0;
    }
  }
  
  isSameMonth (data, useMoment, today) {
    if (useMoment) {
      const day = moment(data.date);
      return today.isSame(day, 'month');
    } else {
      const day = new Date(data.date);
      return today.getMonth() === day.getMonth() &&
        today.getFullYear() === day.getFullYear() ? 1 : 0;
    }
  }
  
  isWithinThirtyDays (data, useMoment, today, thirtyDays) {
    if (useMoment) {
      return moment(data.date).isBetween(today, thirtyDays);
    } else {
      const day = new Date(data.date).getTime();
      return day > today.getTime() && day < thirtyDays.getTime();
    }
  }
  
  processDataset (processName, dataSet, useMoment = true) {
    const tA = performance.now();
    const today = useMoment ? moment(TODAY) : new Date(TODAY);
    const thirtyDays = useMoment ? today.clone().add(30, 'days') : new Date(today.getTime() + (30 * 24 * 60 * 60 * 1000));
    
    const total = dataSet.reduce((count, data) => {
      switch (processName) {
        case 'isToday':
        case 'isSameMonth':
          count += this[processName](data, useMoment, today) ? 1 : 0;
        case 'isWithinThirtyDays':
          count += this.isWithinThirtyDays(data, useMoment, today, thirtyDays) ? 1 : 0;
      }
      return count;
    }, 0);

    const tB = performance.now();
    
    this.updateState(useMoment, processName, {
      time: tB - tA,
      value: total
    });
  }
  
  render () {
    return (
      <div className='app'>
        <div className='generate'>
          <label htmlFor='size'>Size of Data</label>
          <select id='size' ref={c => this.entries = c}>
            <option value={500}>500</option>
            <option value={1000} selected>1,000</option>
            <option value={10000}>10,000</option>
            <option value={25000}>25,000</option>
          </select>
          <button type='button' onClick={this.start}>RUN TEST</button>
        </div>
        <div className='bms'>
          {PROCESSES.map((processName, i) => {
            const sMoment = this.state[`${processName}Moment`];
            const sNative = this.state[`${processName}Native`];
            
            const tMoment = sMoment ? sMoment.time : 0;
            const tNative = sNative ? sNative.time : 0;
            const total = tMoment + tNative;
            const pMoment =  tMoment / total * 100;
            const pNative =  tNative / total * 100;
            const intCheck = sMoment && sNative ? sMoment.value === sNative.value : false;
              
            return (
              <div key={i} className='bms__process'>
                <h2 className='bms__process__title'>{processName}</h2>
                <div className='bms__bm bms__bm--moment'>
                  <div className='bms__bm__graph'>
                    <div className={`bms__bm__graph__fill ${!!this.state.dataSet.length ? '' 
: 'bms__bm__graph__fill--empty'}`} style={{width: pMoment + '%'}} />
                    <div className='bms__bm__graph__value'>{tMoment.toFixed(3)}ms</div>
                  </div>
                  <div className='bms__bm__label'>Moment.js</div>
                </div>
                
                <div className='bms__bm bms__bm--native'>
                  <div className='bms__bm__graph'>
                    <div className={`bms__bm__graph__fill ${!!this.state.dataSet.length ? '' 
: 'bms__bm__graph__fill--empty'}`} style={{width: pNative + '%'}} />
                    <div className='bms__bm__graph__value'>{tNative.toFixed(3)}ms</div>
                  </div>
                  <div className='bms__bm__label'>Native</div>
                </div>
                
                <div className='bms__bm__check'>
                  Integrity Check
                  <span className={`bms__bm__check__status bms__bm__check__status--${intCheck}`}></span>
                </div>
              </div>
            );    
          })}
        </div>
      </div>
    )
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('content')
);
            
          
!
999px
Loading ..................

Console