Code Monkey home page Code Monkey logo

Comments (9)

overtrue avatar overtrue commented on May 23, 2024

嗯,回头看一下,当时考虑到兼容旧版PHP所以这个没敢用,哈哈,感谢

from pinyin.

medz avatar medz commented on May 23, 2024

好的~刚刚我的代码,我做了详细测试,几乎不耗费内存了~只分配当行文件内容内存。

from pinyin.

overtrue avatar overtrue commented on May 23, 2024

嗯,yield就是专门处理这类场景的

from pinyin.

overtrue avatar overtrue commented on May 23, 2024

@medz 我发现一个问题,内存是节省了,可是转换速度下降不少啊,我 clone 了你的代码在我的 mac 上跑你的 test 得到的时间为: 0.62980198860168

稍等长一点的内容,60汉字左右,就需要 0.8 ~ 1 秒了。

from pinyin.

overtrue avatar overtrue commented on May 23, 2024

@medz 以下这份代码:

// test.php
<?php
use Overtrue\Pinyin\Pinyin;

require __DIR__.'/vendor/autoload.php';

$s = microtime(true);
$pinyin = new Pinyin;

var_dump($pinyin->convert('刚刚我的代码,我做了详细测试,几乎不耗费内存了~只分配当行文件内容内存当一个生成器被调用的时候,它返回一个可以被遍历的对象.当你遍历
这个对象的时候(例如通过一个foreach循环),PHP 将会在每次需要值的时候调用生成器函数,并在产生一个值之后保存生成器的状态,这样它就可以在需要产生下一个值的时候恢>复调用状态。
艺术挑战技术,技术启发艺术。将设计师精心雕琢的模板百分百还原在界面与用户流畅交互,不是能简单一键生成。

第一个关键问题是模板上多样的中文字体在网页上如何高效渲染。汉字因其庞大的体积面临压缩和转码的技术难点,在线化一直停滞不前。在设计的先行下,我们工程师必须开拓这
片蛮荒。“我们搭造专门的字体服务器,打散字库,单个储存字体。渲染时仅取内容里的文字,去重后送去字体服务器,效率大幅度提升。”

第二个关键问题是模板的排版如何复刻到界面上。为了让模板达到平衡稳定的视觉韵律,设计稿采用了网格系统。如此对应到 CSS 和 iOS 的规则上非常复杂。工程师进行了繁琐的
换算,与设计师反复磨合,才取了一个兼顾工程规则与设计要求的最佳结果。

技术与艺术的磨合并不平静,是矛盾不断、一波三折。当一个不断抛光打磨的好作品诞生,众人皆欢。当然下一秒我们又会紧绷眉头,因为完美,只能无限接近而无法到达。
'));
echo microtime(true) - $s;

你的代码:0.8 ~ 1
我的代码:0.056 ~ 0.06

from pinyin.

medz avatar medz commented on May 23, 2024

@overtrue 我承认,逐行查找的确会多算好时间~哎~

from pinyin.

medz avatar medz commented on May 23, 2024

没事,我之所以这么改造,是因为我自己有这样的需求,主机没办法载入这么多数组进来。我这份代码只是参考哈~不一定要这么做。

from pinyin.

medz avatar medz commented on May 23, 2024

@overtrue 测试了好久,你说的问题的确是一个大问题~ 时间消耗的太久了,节省了内存,却失去了效率!!有点得不偿失。

from pinyin.

overtrue avatar overtrue commented on May 23, 2024

是的,用户可以把我的切片数量弄多点,这样折中一下内存小一点其实也还好。

from pinyin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.