ClojureScript

Call alength once in areduce and amap

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: 1.9.908
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Accepted

Description

Make a single call to alength in areduce and amap, essentially porting relevant aspects of CLJ-1765 and CLJ-1901 to ClojureScript.

Activity

Hide
Mike Fikes added a comment -
Before:

Benchmarking with V8
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 63 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 83 msecs

Benchmarking with SpiderMonkey
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 26 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 796 msecs

Benchmarking with JavaScriptCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 92 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 98 msecs

Benchmarking with Nashorn
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 1258 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 1433 msecs

Benchmarking with ChakraCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 9 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 67 msecs


After:

Benchmarking with V8
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 56 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 79 msecs

Benchmarking with SpiderMonkey
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 23 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 787 msecs

Benchmarking with JavaScriptCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 93 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 104 msecs

Benchmarking with Nashorn
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 991 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 1252 msecs

Benchmarking with ChakraCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 9 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 71 msecs
Show
Mike Fikes added a comment -
Before:

Benchmarking with V8
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 63 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 83 msecs

Benchmarking with SpiderMonkey
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 26 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 796 msecs

Benchmarking with JavaScriptCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 92 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 98 msecs

Benchmarking with Nashorn
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 1258 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 1433 msecs

Benchmarking with ChakraCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 9 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 67 msecs


After:

Benchmarking with V8
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 56 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 79 msecs

Benchmarking with SpiderMonkey
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 23 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 787 msecs

Benchmarking with JavaScriptCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 93 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 104 msecs

Benchmarking with Nashorn
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 991 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 1252 msecs

Benchmarking with ChakraCore
[arr (to-array (range 1000000))], (reset! x (areduce arr i ret 0 (+ ret (aget arr i)))), 1 runs, 9 msecs
[arr (to-array (range 1000000))], (amap arr i ret (* 10 (aget arr i))), 1 runs, 71 msecs

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: