which is faster ?

A forum for general discussion of the Python programming language.

which is faster ?

Postby vijaykumbhani » Mon Sep 30, 2013 12:01 pm

1. re.match
2. re.sub

Why?

Mekire: Do not just repost your question; clarify your question and make some attempt at showing effort.
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
vijaykumbhani
 
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India

Re: which is faster ?

Postby Kebap » Mon Sep 30, 2013 12:14 pm

re.match is for searching, re.sub is for searching+replacing, how do you compare these?
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: which is faster ?

Postby vijaykumbhani » Mon Sep 30, 2013 1:20 pm

Which case both are working as take same times ?
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
vijaykumbhani
 
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India

Re: which is faster ?

Postby Mekire » Tue Oct 01, 2013 1:12 am

Code: Select all
import timeit

#Code for timing it here.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: which is faster ?

Postby Somelauw » Tue Oct 01, 2013 9:00 pm

I'm not sure what the point of this question is, because match and sub do completely different things.
But just for the sake of answering your question, here are the results.

Code: Select all
>>> import timeit
>>> timeit.timeit("""import re; re.match("hello", "hello")""")
1.7907700538635254
>>> timeit.timeit("""import re; re.sub("hello", "hello", "hello")""")
2.5372841358184814
Join the #python-forum IRC channel on irc.freenode.net!
Somelauw
 
Posts: 72
Joined: Tue Feb 12, 2013 8:30 pm

Re: which is faster ?

Postby vijaykumbhani » Wed Oct 02, 2013 4:17 am

Thanks
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
vijaykumbhani
 
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 7 guests