Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def main(s):
- r = re.compile('\d+')
- rez = ''
- for i in range(100000):
- #s.replace('4','')
- rez = r.sub('',s)
- return rez
- if __name__ == '__main__':
- import time
- for i in range(5):
- start = time.time()
- print main('str4')
- end = time.time()
- print(end - start)
- # vs:
- const performance = require('perf_hooks').performance;
- function Test(str){
- const regex = new RegExp("\d+");// /\d+/gi;
- var rez = 0;
- for(var i=0;i<100000;i++){
- rez = str.replace(regex, '');
- }
- return rez;
- }
- function apply(){
- var time = performance.now();
- console.log(Test('str4'));
- time = performance.now()- time;
- console.log('Время выполнения 1 = ', time);
- }
- for (var a=0;a<5;a++){
- apply();
- }
- // rez: js - 52ms/25ms
- # rez p - 350ms/350ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement