Giter VIP home page Giter VIP logo

nsregularexpression-vs-re2's Introduction

NSRegularExpression-vs-RE2

Tiny Performance benchmark for NSRegularExpression and google/re2

Testcase

  • A large files UTF8 File (~40Mb)
  • Run on Release Mode
  • MacbookPro 15" 2018 - 2.6 GHz 6-Core Intel Core i7
        let tests = [TestCase(name: "URI", regex: "([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?"),
                     TestCase(name: "Email", regex: "([^ @]+)@([^ @]+)"),
                     TestCase(name: "Date", regex: "([0-9][0-9]?)/([0-9][0-9]?)/([0-9][0-9]([0-9][0-9])?)"),
                     TestCase(name: "URI|Email", regex: "([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)")]

        tests.forEach { test in

            measure(name: "RE2") {
                let _ = RegexUtils.regex(withText: content, pattern: test.regex)
            }

            measure(name: "NSRegularExpression") {
                let regex = NSRegularExpression(test.regex)
                let _ = regex.matches(content)
            }
        }

Result

Time: RE2 URI : 0.11845834599989757
Time: NSRegularExpression URI : 0.003419409999878553
-------------------
Time: RE2 Email : 0.13101682099932077
Time: NSRegularExpression Email : 7.166600062191719e-05
-------------------
Time: RE2 Date : 0.12773934000051668
Time: NSRegularExpression Date : 0.0019232759996157256
-------------------
Time: RE2 URI|Email : 0.13327939200007677
Time: NSRegularExpression URI|Email : 7.956900026329095e-05
-------------------

Credit

nsregularexpression-vs-re2's People

Contributors

nghiatranuit avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.