attaswift/BigInt

In debug mode, taking too much time to calculate exponential comparable to Android native BigInteger.

gmtek opened this issue · 5 comments

gmtek commented

Below exponential calculation (2048 bits) is taking around 5s whereas same calculation using Android native BigInteger is taking around 100ms.

        let N = BigUInt("AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B855F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773BCA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB694B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73", radix: 16)!
        let g = BigUInt(2)
        let a = BigUInt("601e4cdbc9ceadbd116fff9331c689b03d9770f5d4da80f8e0fe826f01104e9bb52d68a7bc38519d77d0463f4bc67cf9d13588e03324c7c79a6931dfc3d5b4b3b4014ec08820be1af9f9a056350ccaada53f063568671bd717217be2f90e948d037e00ea348f1bb4f99ca16ca4f11a889529afe80229127b10e85001c6654fbdb805f1122dc1b10679334228ab86ab65a3192f0368ca21f45e966e65adab6bf752844828b25923ad98da909c1b2ffae21625ce6095f0d15601475edd44a7a6979a48339f0265fabe7cb864a56e583c35f838eaa00e676658df7e091a5a3cf346f4df3ce65ed5633b7bb3ea7c2dec982a4ec9c7c6ad9eb3da33cf635ed6094c24", radix: 16)!
        let start = Date()
        let A = g.power(a, modulus: N)
        print("Elapsed time: \(Date().timeIntervalSince(start))")
gmtek commented

In release mode it's taking around 130ms that's awesome. But why this huge difference in debug mode? Note that Android was also in debug mode.

gmtek commented

I agree that debug performance really doesn't matter. Just wondering what operation exactly makes this huge difference in performance between debug and release? I don't see many string manipulation operation either.

Closing some old/resolved issues.