Results 1 to 6 of 6

Thread: Optimize the speed of execution

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Optimize the speed of execution

    Hello,
    I am trying to make a small Java program that uses the regex library provided by Java. However, I have some problems with it.
    Firstly I found the API very slow regex . In fact, I mainly use the replaceAll method of the string class (which uses the regex API) and some processing takes some time (several thousands of iterations / call to replaceAll). Is there a solution to optimize the speed of execution of this method? Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Optimize the speed of execution

    Hello,
    If the pattern is always the same, it is optimized to do that is to create it once and for all, eg if you have something like this:
    for (...) {
    String rs = line.replaceAll("regex", "Replacement");
    }
    You could do this:
    Code:
    Pattern pattern = Pattern.compiles("regex");
    for (...) {
        String rs = pattern.matcher(line).replaceAll("Replacement");
    }

  3. #3
    Join Date
    Dec 2009
    Posts
    192

    Re: Optimize the speed of execution

    Hello,
    If the pattern is always the same, it is optimized to do that is to create it once and for all, eg if you have something like this:
    Naturally, I'll try this track and see the difference .
    You'll have your posts regexp and purpose ...
    for regex looks like stuff like enabling matcher comments:
    - / \ * [\ U0000-\ uffff] *? \ * / -> Java /*...*/ comment
    - / / .* -> Java comment //...
    Thank you for your help . There.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Optimize the speed of execution

    Hello,
    For error. I remember having this problem with java 1.4, it was resolved with a superior version of Java whose implementation was clearly different. Without ever knowing why it shows! Everything I've done at the time was that the regexp was not involved, it was mainly the length of the string on which they made the match that involved a large recursion. by the cons [\ u0000-\ uffff] here is a very large range and includes the sequence here * /, you may not nab the end of comment since the regexp is greedy algorithm by default.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Optimize the speed of execution

    Hello,
    To do it right it uses a quantified "reluctant" (the *?).
    For what interest cons of using [\ u0000-\ uffff] where the point would be the case:
    Code:
    String pattern = "/\\*.*?\\*/";
    Hope this will help you. If not then you can try something other, but before that you need to try this.

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Optimize the speed of execution

    Hello,
    The first point regarding the compilation of pattern. Indeed, the failure to recompile the pattern every time improves the speed of program execution . I can not tell you the percentage / ratio of increase is visible but without calculation so it should still be significant. The only snag some treatment is still long (and yet I use separate threads ...). I use 1.5 in my case and I still make mistakes, but as it has been said above I think it comes from the regex in itself because it only happens on some type of regex type (x | y) *.

Similar Threads

  1. How to optimize Ping?
    By NProtector in forum Technology & Internet
    Replies: 3
    Last Post: 24-11-2010, 04:02 AM
  2. RAM optimize
    By Talish in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 03-08-2010, 11:14 PM
  3. How to optimize the asp.net performance?
    By Mahish in forum Software Development
    Replies: 4
    Last Post: 11-02-2010, 05:09 AM
  4. How to optimize XP
    By Shantanu12 in forum Tips & Tweaks
    Replies: 3
    Last Post: 22-04-2009, 10:46 PM
  5. Network HDD - Speed Optimize
    By Deskmukh in forum Hardware Peripherals
    Replies: 3
    Last Post: 25-02-2009, 01:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,539,840.83829 seconds with 17 queries