Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package media
- import org.junit.BeforeClass
- import org.junit.Test
- import org.apache.commons.lang.time.StopWatch
- import static org.junit.Assert.*
- /**
- * Compares the performance of integer and floating point arithmetic in Groovy.
- *
- * @author <a href="http://johannburkard.de">Johann Burkard</a>
- * @see <a href="http://groovy-programming.com">Groovy Programming</a>
- */
- class LongDivisionTest {
- static final long start = 1
- static final long tests = 100000
- @BeforeClass
- static void setUpBeforeClass() {
- println 'Warming up, this could take 5 s or so'
- (start..tests).each {
- tests / it
- (double) tests / it
- }
- }
- @Test
- void longDivision() {
- StopWatch watch = new StopWatch()
- watch.start()
- (start..tests).each {
- tests / it
- }
- println "long: ${watch.time}"
- }
- @Test
- void doubleDivision() {
- StopWatch watch = new StopWatch()
- watch.start()
- (start..tests).each {
- (double) tests / it
- }
- println "double: ${watch.time}"
- }
- @Test
- void deepLongDivision() {
- deepLongDivision1()
- }
- void deepLongDivision1() {
- deepLongDivision2()
- }
- void deepLongDivision2() {
- deepLongDivision3()
- }
- void deepLongDivision3() {
- StopWatch watch = new StopWatch()
- watch.start()
- (start..tests).each {
- tests / it
- }
- println "long (deep): ${watch.time}"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment