PHP and the million array baby

前端 未结 4 1126
一个人的身影
一个人的身影 2021-02-19 19:37

Imagine you have the following array of integers:

array(1, 2, 1, 0, 0, 1, 2, 4, 3, 2, [...] );

The integers go on up to one million entries; on

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 20:12

    I can't randomly generate it every time because it should be consistent and always have the same values at the same indexes.

    Have you ever read up on pseudo-random numbers? There's this little thing called a seed which addresses this issue.

    Also benchmark your options and claims. Have you timed the file_get_contents vs. the json_decode? There is a trade-off to be made here between storage and access costs. Eg. if your numbers are 0..9 (or 0..255) then it may be easier to store them in a 2Mb string and use an access function on this. 2Mb will load faster whether from the FS or APC.

提交回复
热议问题