diff --git a/scripts/benchmark_moment.js b/scripts/benchmark_moment.js new file mode 100644 index 0000000..11c4428 --- /dev/null +++ b/scripts/benchmark_moment.js @@ -0,0 +1,27 @@ +const moment = require('moment'); + +const ITERATIONS = 1000000; + +console.log(`Running benchmark with ${ITERATIONS} iterations...`); + +// Benchmark Moment.js +const startMoment = process.hrtime(); +for (let i = 0; i < ITERATIONS; i++) { + moment() + .valueOf() + .toString(); +} +const endMoment = process.hrtime(startMoment); +const timeMoment = endMoment[0] * 1000 + endMoment[1] / 1000000; + +// Benchmark Date.now() +const startDate = process.hrtime(); +for (let i = 0; i < ITERATIONS; i++) { + Date.now().toString(); +} +const endDate = process.hrtime(startDate); +const timeDate = endDate[0] * 1000 + endDate[1] / 1000000; + +console.log(`Moment.js: ${timeMoment.toFixed(2)}ms`); +console.log(`Date.now(): ${timeDate.toFixed(2)}ms`); +console.log(`Improvement: ${(timeMoment / timeDate).toFixed(2)}x faster`); diff --git a/src/services/BackgroundService.js b/src/services/BackgroundService.js index f88d78d..0db92a1 100644 --- a/src/services/BackgroundService.js +++ b/src/services/BackgroundService.js @@ -1,7 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import BackgroundTimer from 'react-native-background-timer'; import PushNotification from 'react-native-push-notification'; -import moment from 'moment'; import {USER_AGENT_DESKTOP, WEB_PLATFORM_DESKTOP} from '../Constants'; import {escapeRegExp} from '../Utils'; @@ -55,12 +54,7 @@ export const checkUrlForText = async checkUrlForTextData => { }); } - await AsyncStorage.setItem( - 'lastChecked', - moment() - .valueOf() - .toString(), - ); + await AsyncStorage.setItem('lastChecked', Date.now().toString()); } catch (error) { console.log(error); }