Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

ThisThis recent post reminded me that AbsoluteTime is a fast kernel function.

Using the RandomDates function from Leonid's post:

dates = RandomDates[500000]; Needs["Calendar`"] rls = Thread[ Range[0, 6] -> {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} ]; Timing[result1 = DayOfWeek /@ dates;] Timing[result2 = Mod[Quotient[AbsoluteTime /@ dates, 60^2 24], 7] /. rls;] result1 === result2 
{37.783, Null} {0.921, Null} True 

~ 41X speed-up.

This recent post reminded me that AbsoluteTime is a fast kernel function.

Using the RandomDates function from Leonid's post:

dates = RandomDates[500000]; Needs["Calendar`"] rls = Thread[ Range[0, 6] -> {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} ]; Timing[result1 = DayOfWeek /@ dates;] Timing[result2 = Mod[Quotient[AbsoluteTime /@ dates, 60^2 24], 7] /. rls;] result1 === result2 
{37.783, Null} {0.921, Null} True 

~ 41X speed-up.

This recent post reminded me that AbsoluteTime is a fast kernel function.

Using the RandomDates function from Leonid's post:

dates = RandomDates[500000]; Needs["Calendar`"] rls = Thread[ Range[0, 6] -> {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} ]; Timing[result1 = DayOfWeek /@ dates;] Timing[result2 = Mod[Quotient[AbsoluteTime /@ dates, 60^2 24], 7] /. rls;] result1 === result2 
{37.783, Null} {0.921, Null} True 

~ 41X speed-up.

Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

This recent post reminded me that AbsoluteTime is a fast kernel function.

Using the RandomDates function from Leonid's post:

dates = RandomDates[500000]; Needs["Calendar`"] rls = Thread[ Range[0, 6] -> {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} ]; Timing[result1 = DayOfWeek /@ dates;] Timing[result2 = Mod[Quotient[AbsoluteTime /@ dates, 60^2 24], 7] /. rls;] result1 === result2 
{37.783, Null} {0.921, Null} True 

~ 41X speed-up.