Optimization challenge: Count Characters

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 9200 Views - Last Post: 01 October 2012 - 03:26 PM

#16 rfs02  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 26
  • View blog
  • Posts: 70
  • Joined: 30-September 12

Re: Optimization challenge: Count Characters

Posted 01 October 2012 - 07:24 AM

Very late to the game at this point.

With inspiration from the previous replies (and using both Parallel and unsafe)

Spoiler

Was This Post Helpful? 0
  • +
  • -

#17 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3160
  • View blog
  • Posts: 9,531
  • Joined: 05-May 12

Re: Optimization challenge: Count Characters

Posted 01 October 2012 - 08:35 AM

Won't that code miss some characters if the string length cannot be evenly divided by the number of partitions?

This post has been edited by Skydiver: 01 October 2012 - 08:36 AM

Was This Post Helpful? 0
  • +
  • -

#18 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 994
  • View blog
  • Posts: 2,380
  • Joined: 04-October 09

Re: Optimization challenge: Count Characters

Posted 01 October 2012 - 09:55 AM

The challenge requires strings of 10,000 characters. Yes, it's optimized specifically for this challenge, but that's the challenge :)
Was This Post Helpful? 0
  • +
  • -

#19 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1275
  • View blog
  • Posts: 2,837
  • Joined: 05-April 11

Re: Optimization challenge: Count Characters

Posted 01 October 2012 - 12:42 PM

View PostMomerath, on 01 October 2012 - 04:55 PM, said:

The challenge requires strings of 10,000 characters. Yes, it's optimized specifically for this challenge, but that's the challenge :)


I think you should change the stride of your example to str.Length / Enviroment.ProcessorCount, that would prevent the need to start many unnecessary threads while still making every thread work 100%
Was This Post Helpful? 0
  • +
  • -

#20 rfs02  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 26
  • View blog
  • Posts: 70
  • Joined: 30-September 12

Re: Optimization challenge: Count Characters

Posted 01 October 2012 - 01:44 PM

View PostCasiOo, on 01 October 2012 - 12:42 PM, said:

View PostMomerath, on 01 October 2012 - 04:55 PM, said:

The challenge requires strings of 10,000 characters. Yes, it's optimized specifically for this challenge, but that's the challenge :)


I think you should change the stride of your example to str.Length / Enviroment.ProcessorCount, that would prevent the need to start many unnecessary threads while still making every thread work 100%


Agreed, you just need to make sure 10,000 is divisible by your number of processors. I did test it and it is about 5-10% faster than running with 100 threads.
Was This Post Helpful? 0
  • +
  • -

#21 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3160
  • View blog
  • Posts: 9,531
  • Joined: 05-May 12

Re: Optimization challenge: Count Characters

Posted 01 October 2012 - 03:26 PM

View PostMomerath, on 01 October 2012 - 09:55 AM, said:

The challenge requires strings of 10,000 characters. Yes, it's optimized specifically for this challenge, but that's the challenge :)


Not quite. Quoting from the OP:

Quote

The Challenge
In this challenge you have to optimize a very basic method which is called ten thousand times. The method counts how many times one character appears in a string.


It's the function call that maybe called 10,000 times according to the challenge. It just happened that the test string was a 10,000 random character string, but the string could easily have been a 100 character string or a 123456 character string.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2