首页 \ 问答 \ 使用直接ado.net与ORM的性能提升?(Performance gains using straight ado.net vs an ORM?)

使用直接ado.net与ORM的性能提升?(Performance gains using straight ado.net vs an ORM?)

如果我将应用程序的数据访问部分从nhiberate替换为直接ado.net,会获得任何性能提升吗?

我知道NHibernate在其核心使用ado.net!


would i get any performance gains if i replace my data access part of the application from nhiberate to straight ado.net ?

i know that NHibernate uses ado.net at its core !


原文:https://stackoverflow.com/questions/1936807
更新时间:2022-12-08 17:12

最满意答案

我没有在列表和arraylist中摆弄索引,而是将实现更改为使用通用Dictionary<tkey, tvalue>因此索引可以是简单的查找。 请记住,这会不断添加项目,因此如果经常调用,您将耗尽内存。 这里没有清理。

class TimedSingleton
{
    // have a dictonary to hold the seconds
    // and the instance so we can lookup
    private static Dictionary<int, TimedSingleton> AddedPositions = new Dictionary<int, TimedSingleton>();

    private static DateTime _startTime = DateTime.Now;

    protected TimedSingleton()
    {
    }

    public static TimedSingleton Instance()
    {
        // divide by 5
        int index = (int)DateTime.Now.Subtract(_startTime).TotalSeconds / 5;
        Debug.WriteLine(index);

        // 
        TimedSingleton result;
        // if you're going to multhreed this
        lock(AddedPositions)
        {
            // try to get the index seconds ...
            if (!AddedPositions.TryGetValue(index,out result))
            {
                // not happened
                Debug.WriteLine("Created new instance");
                result = new TimedSingleton();
                // store it for later
                AddedPositions.Add(index, result);
            }
            else
            {
                // result has now a previous instance
                Debug.WriteLine("from cache");
            }
        }
        return result;
    }
}

Instead of the fiddling with the indexes in a list and arraylist I changed your implementation to use a generic Dictionary<tkey, tvalue> instead so the index can be a simple lookup. Keep in mind that this keeps adding items so if called often enough you'll run out of memory. There is no clean up here.

class TimedSingleton
{
    // have a dictonary to hold the seconds
    // and the instance so we can lookup
    private static Dictionary<int, TimedSingleton> AddedPositions = new Dictionary<int, TimedSingleton>();

    private static DateTime _startTime = DateTime.Now;

    protected TimedSingleton()
    {
    }

    public static TimedSingleton Instance()
    {
        // divide by 5
        int index = (int)DateTime.Now.Subtract(_startTime).TotalSeconds / 5;
        Debug.WriteLine(index);

        // 
        TimedSingleton result;
        // if you're going to multhreed this
        lock(AddedPositions)
        {
            // try to get the index seconds ...
            if (!AddedPositions.TryGetValue(index,out result))
            {
                // not happened
                Debug.WriteLine("Created new instance");
                result = new TimedSingleton();
                // store it for later
                AddedPositions.Add(index, result);
            }
            else
            {
                // result has now a previous instance
                Debug.WriteLine("from cache");
            }
        }
        return result;
    }
}

相关问答

更多
  • 你当然可以,但我不推荐它。 使用基于时间的索引的优点是删除索引会完全擦除磁盘中的数据而不会产生任何伪影。 从索引中删除类型与删除与该类型相关的所有单个文档相同,这意味着文档将被简单地标记为已删除,并最终(可能)随时间合并。 删除的文档仍然是搜索性能的负担,因为它们是软删除并且即使在“删除”时占用索引中的空间。 如果您不关心这一点,那么我会说没有什么能阻止您创建基于时间的类型并删除它们,但是您将失去保持单独索引所带来的所有性能改进。 You certainly could, but I wouldn't re ...
  • 这里有两个部分, 访问令牌和刷新令牌 。 访问令牌在通过expires_in属性指定的时间间隔后到期。 如果刷新令牌未使用的时间超过28天,则刷新令牌可能会过期。 每次使用刷新令牌请求新的访问令牌时,定时器都会重置,并且在刷新令牌到期前还有28天。 如果您在28天内定期获得新的访问令牌,则可以假设无限期地使用相同的刷新令牌。 获取初始访问令牌和刷新令牌的HTTP请求示例(用星号标记的值): POST /oauth/token HTTP/1.1 Host: podio.com Content-Type: ap ...
  • 不知道这是否是一个可用的答案,但是当我构建一个rudimetary游戏时,我以这种方式使它成为多线程: 当用户执行某些操作时,事件线程会将消息推送到线程安全消息队列中。 “游戏”线程读取消息队列,处理数据,将输出呈现到屏幕上然后休眠一段时间。 以这种方式,事件线程可以保持阻塞,直到用户输入发生,同时游戏逻辑和输入/输出以简单的同步方式完成。 Windows有一个你可以使用的线程库(虽然我还没有使用过那个,因为我总是在linux上使用boost线程或posix线程。) Don't know if this i ...
  • 我没有在列表和arraylist中摆弄索引,而是将实现更改为使用通用Dictionary因此索引可以是简单的查找。 请记住,这会不断添加项目,因此如果经常调用,您将耗尽内存。 这里没有清理。 class TimedSingleton { // have a dictonary to hold the seconds // and the instance so we can lookup private static Dictionary
  • 有可能使用redis的排序集。 您可以继续按照排序集中的时间推送数据。 例如 zadd queue 1 value1 zadd queue 2 value2 zadd queue 3 value3 zadd queue 4 value4 zadd queue 5 value5 让我们说1到5是你的价值观(以小时计的时间)。 现在,如果您在第3小时查询,您将会这样查询。 zrangebyscore queue 3 +inf 这将回报你 value3,value4,value5作为结果。 随着时间的推移,这 ...
  • 我现在写的软件的平均寿命可能是几天。 (我写了很多脚本,所以我可能会感觉不正常。;-)但是我使用的核心系统现在可能已经有15到20年了。 底层操作系统大约有30年的历史。 无论是老软件还是年轻软件都没有任何内在错误。 实际上,当软件可以适应新用途时,软件会老化。 在功能部件之间具有抽象层使得更换系统中的功能更容易。 例如,我们已经在我们的系统上浏览了几个不同的磁带库,现在我们正在考虑将来使用磁盘存档。 由于我们系统的“归档”部分位于抽象层之后,我们可以非常轻松地替换它而无需替换系统的其余部分。 如果可能,最 ...
  • 我正在使用AlarmManager就像你想在我的项目中一样。 在项目中,我可以安排单次或每日,每周,每月,每年的警报。 实际上它的工作正常,但操作系统可以转换警报电池效率,有时可能会延迟1分钟。 如果你在AlarmManager.html#setRepeating中读到这个: 注意:从API 19开始,所有重复警报都不准确。 如果您的应用程序需要精确的交付时间,那么它必须使用一次性精确警报,每次重新安排如上所述。 targetSdkVersion早于API 19的旧应用程序将继续将所有警报(包括重复警报)视 ...
  • 简单回答的简单问题...我只是忘了在Discover部分的右上角设置时间戳来显示过去的数据: Simple question with simple answer... I just forgot to set the timepicker in the Right-top of the Discover part to show past data:
  • 这是CFUUID和NSUUID使用的底层库的手册页 。 它包含基于时间的创建功能: #include uuid_generate_time(uuid_t); 它也包含在iOS中。 Here's the man page of the underlying library used by CFUUID and NSUUID. It contains the time based creation function: #include uuid_ge ...
  • 对于基于时间的移动,您需要从上一帧开始经过的时间( delta )和每次像素的速度。 ( delta值应该可以从游戏中的任何位置访问。) 要获得自上一帧以来的时间(以秒为单位),请执行以下操作(假设Game是您的全局游戏对象): Game.now = Date.now(); Game.delta = Game.now - Game.past/1000 Game.past = Game.now; 您可以将delta值乘以不同对象的每个速度以获得行进距离。 var distance = Game.delta ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)