Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starlark: use Math.floorDiv in Starlark.floordiv
`Math.floorDiv` does multiplication to compute a remainder. JVM is supposed to [detect a pair of division and remainder](http://hg.openjdk.java.net/jdk9/jdk9/hotspot/file/jdk-9+181/src/share/vm/opto/compile.cpp#l3176) when C2 is kicked in, but somehow it seems to not do it on my laptop. Benchmark can be made a little even more faster by [adding `yl - 1` instead of multiplication](https://git.io/JIYY6) but better keep implementation simple. Anyway, using `Math.floorDiv` is a safe bet. ``` def test(): for i in range(10): print(i) for j in range(1000000): 1 // 100 1000 // 20 -1 // 30 -33 // 9 500000 / 22 1 // 100 1000 // 20 1 // 30 3306 // 11 500000 // 22 test() ``` ``` A: n=80 mean=5.149 std=0.317 se=0.035 min=4.709 med=5.102 B: n=80 mean=4.634 std=0.280 se=0.031 min=4.234 med=4.552 B/A: 0.900 0.883..0.918 (95% conf) ``` Closes #12621. PiperOrigin-RevId: 345857371
- Loading branch information